Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/net/doppelr/lemonmates/AllCreativeModeTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,11 @@ public class AllCreativeModeTabs {
public static final DeferredRegister<CreativeModeTab> 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<CreativeModeTab, CreativeModeTab> BASE_CREATIVE_TAB = CREATIVE_MODE_TABS.register("base",
() -> CreativeModeTab.builder()
.title(Component.translatable("itemGroup." + LemonMates.MOD_ID + ".base"))
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/doppelr/lemonmates/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,7 +112,7 @@ public class ModBlocks {

public static final DeferredBlock<Block> LEMONADE_GLASS = registerBlock("lemonade_glass",
() -> new ModDrinkingGlassBlock(BlockBehaviour.Properties.of()
.sound(SoundType.GLASS)
.sound(SoundType.GLASS).pushReaction(PushReaction.DESTROY)
));
public static final DeferredBlock<Block> LEMONADE_GLASS_DECORATED = registerBlock("lemonade_glass_decorated",
() -> new ModDrinkingGlassBlock(BlockBehaviour.Properties.of()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@
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;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ModDrinkingGlassBlock extends HorizontalDirectionalBlock {
public class ModDrinkingGlassBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock {
public static final MapCodec<ModDrinkingGlassBlock> CODEC = simpleCodec(ModDrinkingGlassBlock::new);
private static final VoxelShape SHAPE = Block.box(5.0, 0, 5, 11, 7, 11);

Expand All @@ -52,6 +58,7 @@ public class ModDrinkingGlassBlock extends HorizontalDirectionalBlock {
public static final EnumProperty<FruitSlices> FRUIT_SLICE = AllBlockStateProperties.FRUIT_SLICES;
public static final EnumProperty<UmbrellaVariants> 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);
Expand All @@ -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) {}
Expand Down Expand Up @@ -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);
Expand All @@ -273,15 +294,24 @@ 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);
}

@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> 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
Expand All @@ -302,6 +332,6 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> 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);
}
}
27 changes: 24 additions & 3 deletions src/main/java/net/doppelr/lemonmates/block/ModJugBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ApplicableFluidsToFluidContainer> 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
Expand Down Expand Up @@ -67,6 +88,6 @@ protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos,

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(JUG_LEVEL, FLUID, CAN_POUR);
builder.add(JUG_LEVEL, FLUID, CAN_POUR, WATERLOGGED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, LemonMates.MOD_ID);
Expand All @@ -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<BlockEntityType<LemonadeglassEntity>> 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);
}
Expand Down

This file was deleted.

Loading