From bc8614dedd019992c9253cafc691035f76bfed63 Mon Sep 17 00:00:00 2001 From: 3944Realms Date: Sat, 8 Feb 2025 02:07:11 +0800 Subject: [PATCH] =?UTF-8?q?Update=20to=201.4.1=20MirrorBlock=E4=B8=ADupdat?= =?UTF-8?q?eShape=E6=96=B9=E6=B3=95=E9=87=8C=E4=B8=80=E5=A0=86=E7=83=82?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=88=AB=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- src/generated/resources/.cache/cache | 6 + .../models/item/large_mirror.json | 6 + .../models/item/massive_mirror.json | 6 + .../loot_tables/blocks/large_mirror.json | 20 ++ .../loot_tables/blocks/massive_mirror.json | 20 ++ .../loot_tables/blocks/mirror.json | 20 ++ .../loot_tables/blocks/tall_mirror.json | 20 ++ .../modernlifepatch/EventHandler.java | 3 + .../modernlifepatch/MLPCreativeTab.java | 2 - .../content/blocks/ModBlocks.java | 4 + .../blocks/type/mirror/MirrorBlock.java | 300 +++++++++++++++--- .../type/mirror/shape/LargeMirrorShape.java | 2 - .../type/mirror/shape/MassiveMirrorShape.java | 11 +- .../content/items/ModItems.java | 2 + .../datagen/DataGeneratorHandler.java | 1 + .../provider/ModItemModelProvider.java | 2 + .../datagen/provider/ModLootTabProvider.java | 39 +++ .../provider/loot/ModBlockLootTables.java | 22 ++ .../mixin/block/common/MixinSeedSpreader.java | 5 - .../block/kitchen/MixinRefrigerator.java | 2 - 21 files changed, 442 insertions(+), 53 deletions(-) create mode 100644 src/generated/resources/assets/modernlifepatch/models/item/large_mirror.json create mode 100644 src/generated/resources/assets/modernlifepatch/models/item/massive_mirror.json create mode 100644 src/generated/resources/data/modernlifepatch/loot_tables/blocks/large_mirror.json create mode 100644 src/generated/resources/data/modernlifepatch/loot_tables/blocks/massive_mirror.json create mode 100644 src/generated/resources/data/modernlifepatch/loot_tables/blocks/mirror.json create mode 100644 src/generated/resources/data/modernlifepatch/loot_tables/blocks/tall_mirror.json create mode 100644 src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModLootTabProvider.java create mode 100644 src/main/java/com/r3944realms/modernlifepatch/datagen/provider/loot/ModBlockLootTables.java diff --git a/gradle.properties b/gradle.properties index f9c318d..81bf43e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ org.gradle.daemon=false mod.id = modernlifepatch mod.group = com.r3944realms.modernlifepatch mod.author = r3944Realms -mod.version = 1.18.2-1.4.0 \ No newline at end of file +mod.version = 1.18.2-1.4.1 \ No newline at end of file diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index e8f652f..0be487a 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -1,4 +1,10 @@ 38eeb75da0923717638f16acc5c7068aecba156e assets/modernlifepatch/lang/en_us.json bab598e47751847b120edd8d3418781229ec5fd6 assets/modernlifepatch/lang/zh_cn.json +ac9cec2e51193a3ebaa165fe91c9bb3f9f3fcc32 assets/modernlifepatch/models/item/large_mirror.json +de63e31ba044ddc8d09dd10945a560d414e185c4 assets/modernlifepatch/models/item/massive_mirror.json 80cb85eae418087ea09e8b0d34289b3faf7f0faf assets/modernlifepatch/models/item/mirror.json ddaaed0180f28afb8dfa1c4270e9872360aca2a7 assets/modernlifepatch/models/item/tall_mirror.json +9a71f6635f4ffa1441d5f3120a7423cf2fdc2f1f data/modernlifepatch/loot_tables/blocks/large_mirror.json +4d0d15aa540872b16a0d933522a63822564772e6 data/modernlifepatch/loot_tables/blocks/massive_mirror.json +0d9ab0fd3bb217e2cba98c4d870a49aad11df4ea data/modernlifepatch/loot_tables/blocks/mirror.json +2e8f6832411b91b57fe84a63e0f3fe5c855cf732 data/modernlifepatch/loot_tables/blocks/tall_mirror.json diff --git a/src/generated/resources/assets/modernlifepatch/models/item/large_mirror.json b/src/generated/resources/assets/modernlifepatch/models/item/large_mirror.json new file mode 100644 index 0000000..9e8837e --- /dev/null +++ b/src/generated/resources/assets/modernlifepatch/models/item/large_mirror.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "modernlifepatch:item/large_mirror_item" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/modernlifepatch/models/item/massive_mirror.json b/src/generated/resources/assets/modernlifepatch/models/item/massive_mirror.json new file mode 100644 index 0000000..3a4cadc --- /dev/null +++ b/src/generated/resources/assets/modernlifepatch/models/item/massive_mirror.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "modernlifepatch:item/massive_mirror_item" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/modernlifepatch/loot_tables/blocks/large_mirror.json b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/large_mirror.json new file mode 100644 index 0000000..f4fe85b --- /dev/null +++ b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/large_mirror.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1.0, + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "name": "modernlifepatch:large_mirror" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/modernlifepatch/loot_tables/blocks/massive_mirror.json b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/massive_mirror.json new file mode 100644 index 0000000..f0fb427 --- /dev/null +++ b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/massive_mirror.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1.0, + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "name": "modernlifepatch:massive_mirror" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/modernlifepatch/loot_tables/blocks/mirror.json b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/mirror.json new file mode 100644 index 0000000..07999bf --- /dev/null +++ b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/mirror.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1.0, + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "name": "modernlifepatch:mirror" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/modernlifepatch/loot_tables/blocks/tall_mirror.json b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/tall_mirror.json new file mode 100644 index 0000000..39e1277 --- /dev/null +++ b/src/generated/resources/data/modernlifepatch/loot_tables/blocks/tall_mirror.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1.0, + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "name": "modernlifepatch:tall_mirror" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/r3944realms/modernlifepatch/EventHandler.java b/src/main/java/com/r3944realms/modernlifepatch/EventHandler.java index a882c0d..e65f6ca 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/EventHandler.java +++ b/src/main/java/com/r3944realms/modernlifepatch/EventHandler.java @@ -2,6 +2,7 @@ package com.r3944realms.modernlifepatch; import com.dairymoose.modernlife.core.CustomBlocks; import com.r3944realms.modernlifepatch.client.event.CreativeScreenEvents; +import com.r3944realms.modernlifepatch.content.blocks.ModBlocks; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.server.packs.repository.Pack; @@ -28,6 +29,8 @@ public abstract class EventHandler { @OnlyIn(Dist.CLIENT) public static void onClientSetup(FMLClientSetupEvent event) { event.enqueueWork(() -> { + ItemBlockRenderTypes.setRenderLayer(ModBlocks.MASSIVE_MIRROR.get(), RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(ModBlocks.LARGE_MIRROR.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(CustomBlocks.BLOCK_ACACIA_CHAIR.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(CustomBlocks.BLOCK_BIRCH_CHAIR.get(), RenderType.cutout()); ItemBlockRenderTypes.setRenderLayer(CustomBlocks.BLOCK_DARK_OAK_CHAIR.get(), RenderType.cutout()); diff --git a/src/main/java/com/r3944realms/modernlifepatch/MLPCreativeTab.java b/src/main/java/com/r3944realms/modernlifepatch/MLPCreativeTab.java index 161adff..f7263ae 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/MLPCreativeTab.java +++ b/src/main/java/com/r3944realms/modernlifepatch/MLPCreativeTab.java @@ -3,9 +3,7 @@ package com.r3944realms.modernlifepatch; import com.dairymoose.modernlife.core.CustomBlocks; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; -import net.minecraftforge.common.Tags; import org.jetbrains.annotations.NotNull; public class MLPCreativeTab extends CreativeModeTab { diff --git a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/ModBlocks.java b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/ModBlocks.java index 81ae7e3..72a945c 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/ModBlocks.java +++ b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/ModBlocks.java @@ -21,6 +21,10 @@ public class ModBlocks { () -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.COMMON_MIRROR)); public static final RegistryObject TALL_MIRROR = BLOCKS.register("tall_mirror", () -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.TELL_MIRROR)); + public static final RegistryObject LARGE_MIRROR= BLOCKS.register("large_mirror", + () -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.LARGE_MIRROR)); + public static final RegistryObject MASSIVE_MIRROR = BLOCKS.register("massive_mirror" , + () -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.MASSIVE_MIRROR)); @SuppressWarnings("UnusedReturnValue") public static RegistryObject registerBlockItem(String name , RegistryObject block){ return ModItems.ITEMS.register(name,() -> new BlockItem(block.get(),new Item.Properties())); diff --git a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/MirrorBlock.java b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/MirrorBlock.java index a7b4f2c..b724aa3 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/MirrorBlock.java +++ b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/MirrorBlock.java @@ -1,37 +1,47 @@ package com.r3944realms.modernlifepatch.content.blocks.type.mirror; +import com.r3944realms.modernlifepatch.common.ModTags; import com.r3944realms.modernlifepatch.content.blocks.blockstate.ModBlockStateProperties; import com.r3944realms.modernlifepatch.content.blocks.entities.type.mirror.MirrorBlockEntity; import com.r3944realms.modernlifepatch.content.blocks.type.mirror.shape.IMirrorShape; +import com.r3944realms.modernlifepatch.content.items.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; 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.LevelReader; -import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; 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.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public class MirrorBlock extends HorizontalDirectionalBlock implements EntityBlock { public static final EnumProperty PART = ModBlockStateProperties.MIRROR_PART; public final MirrorPart.MirrorType mirrorType; - public MirrorBlock(Properties pProperties, MirrorPart.MirrorType mirrorType) { + public MirrorBlock(Properties pProperties, MirrorPart.@NotNull MirrorType mirrorType) { super(pProperties); MirrorPart mirrorPart = null; this.mirrorType = mirrorType; @@ -44,18 +54,254 @@ public class MirrorBlock extends HorizontalDirectionalBlock implements EntityBlo this.registerDefaultState(this.stateDefinition.any().setValue(PART, mirrorPart)); } + // 控制是否能够在该放置放置方块, 如果不能满足放置要求则返回null(借鉴于原版的梯子方块) @Nullable @Override public BlockState getStateForPlacement(@NotNull BlockPlaceContext pContext) { + final BlockPos clickedPos = pContext.getClickedPos(); + final Level level = pContext.getLevel(); + final Direction horizontalDirection = pContext.getHorizontalDirection(); return switch (mirrorType) { - case COMMON_MIRROR -> this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection()); - case TELL_MIRROR -> { - BlockPos above = pContext.getClickedPos().above(); - Level level = pContext.getLevel(); - yield level.getBlockState(above).canBeReplaced(pContext) ? this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection()) : null; + case COMMON_MIRROR -> { + // 检查后部分是否有合法的支撑方块 + BlockPos behind = clickedPos.relative(horizontalDirection); + + boolean flag = !level.getBlockState(behind).isAir() && level.getBlockState(behind).isSolidRender(level, behind); + yield flag ? this.defaultBlockState().setValue(FACING, horizontalDirection) : null; } - case LARGE_MIRROR -> super.getStateForPlacement(pContext); - case MASSIVE_MIRROR -> super.getStateForPlacement(pContext); + case TELL_MIRROR -> { + // 检查上部分是不是有阻挡 + BlockPos above = clickedPos.above(); + boolean flag1 = level.getBlockState(above).canBeReplaced(pContext); + // 检查上部分是否有合法的支撑方块 + BlockPos relative = above.relative(horizontalDirection); + boolean flag2 = !level.getBlockState(relative).isAir() && level.getBlockState(relative).isSolidRender(level, relative); + yield flag1 && flag2 ? this.defaultBlockState().setValue(FACING, horizontalDirection) : null; + } + case LARGE_MIRROR -> { + // 检查空间是否足够2x2 + BlockPos headLeft = clickedPos.above(), + footRight = clickedPos.relative(pContext.getHorizontalDirection().getCounterClockWise().getOpposite()), + headRight = footRight.above(); + boolean flag1 = level.getBlockState(headLeft).canBeReplaced(pContext) && + level.getBlockState(footRight).canBeReplaced(pContext) && + level.getBlockState(headRight).canBeReplaced(pContext); + // 检查其它部分是否有合法的支撑方块 + BlockPos headLeftSupport = headLeft.relative(horizontalDirection), + headRightSupport = headRight.relative(horizontalDirection), + footRightSupport = footRight.relative(horizontalDirection); + boolean flag2 = (!level.getBlockState(headLeftSupport).isAir() && level.getBlockState(headLeftSupport).isSolidRender(level, headLeftSupport)) && + (!level.getBlockState(footRightSupport).isAir() && level.getBlockState(footRightSupport).isSolidRender(level, footRightSupport)) && + (!level.getBlockState(headRightSupport).isAir() && level.getBlockState(headRightSupport).isSolidRender(level, headRightSupport)); + yield flag1 && flag2 ? this.defaultBlockState().setValue(FACING, horizontalDirection) : null; + } + case MASSIVE_MIRROR -> { + // 检查空间是否足够2x3 + BlockPos footLeft = clickedPos.relative(pContext.getHorizontalDirection().getCounterClockWise()), + headLeft = footLeft.above(), + footRight = clickedPos.relative(pContext.getHorizontalDirection().getCounterClockWise().getOpposite()), + headMiddle = clickedPos.above(), + headRight = footRight.above(); + boolean flag1 = level.getBlockState(headLeft).canBeReplaced(pContext) && + level.getBlockState(footRight).canBeReplaced(pContext) && + level.getBlockState(footLeft).canBeReplaced(pContext) && + level.getBlockState(headMiddle).canBeReplaced(pContext) && + level.getBlockState(headRight).canBeReplaced(pContext); + // 检查其它部分是否有合法的支撑方块 + BlockPos headLeftSupport = headLeft.relative(horizontalDirection), + headMiddleSupport = headMiddle.relative(horizontalDirection), + headRightSupport = headRight.relative(horizontalDirection), + footLeftSupport = footLeft.relative(horizontalDirection), + footRightSupport = footRight.relative(horizontalDirection); + boolean flag2 = (!level.getBlockState(headLeftSupport).isAir() && level.getBlockState(headLeftSupport).isSolidRender(level, headLeftSupport)) && + (!level.getBlockState(footRightSupport).isAir() && level.getBlockState(footRightSupport).isSolidRender(level, footRightSupport)) && + (!level.getBlockState(headRightSupport).isAir() && level.getBlockState(headRightSupport).isSolidRender(level, headRightSupport)) && + (!level.getBlockState(headMiddleSupport).isAir() && level.getBlockState(headMiddleSupport).isSolidRender(level, headMiddleSupport)) && + (!level.getBlockState(footLeftSupport).isAir() && level.getBlockState(footLeftSupport).isSolidRender(level, footLeftSupport)); + yield flag1 && flag2 ? this.defaultBlockState().setValue(FACING, horizontalDirection) : null; + } + }; + } + + // 控制当方块结构不完整时,破坏另一结构的方块(借鉴于于原版的床破坏逻辑) + @Override + public @NotNull BlockState updateShape(@NotNull BlockState pState, @NotNull Direction pDirection, @NotNull BlockState pNeighborState, @NotNull LevelAccessor pLevel, @NotNull BlockPos pCurrentPos, @NotNull BlockPos pNeighborPos) { + final boolean canSelfNotSurvive = !pState.canSurvive(pLevel, pCurrentPos); + final Direction facing = pState.getValue(FACING); + final MirrorPart part = pState.getValue(PART); + return switch (mirrorType) { + case COMMON_MIRROR -> (pDirection == facing && canSelfNotSurvive) ? + Blocks.AIR.defaultBlockState() : pState; + case TELL_MIRROR -> { + boolean isFoot = part == MirrorPart.FOOT; + BlockPos otherPartPos = isFoot ? pCurrentPos.above() : pCurrentPos.below(); + BlockState otherPartState = pLevel.getBlockState(otherPartPos); + // 当自身无法存活时,检查另一部分是否存在,并一起破坏 + boolean flag = otherPartState.is(this) && otherPartState.getValue(PART) == (isFoot ? MirrorPart.HEAD : MirrorPart.FOOT); + if (canSelfNotSurvive) { + // 破坏自身 + pLevel.destroyBlock(pCurrentPos, true); + // 若另一部分存在,则破坏另一部分 +// if (!flag) { + pLevel.destroyBlock(otherPartPos, false); +// } + yield Blocks.AIR.defaultBlockState(); + } + if(!flag) { + pLevel.destroyBlock(otherPartPos, true); + pLevel.destroyBlock(pCurrentPos, false); + } + // 如果另一部分被破坏,自身也需更新 + yield flag ? pState : Blocks.AIR.defaultBlockState(); + // 另一部分不存在时破坏自身 + } + case LARGE_MIRROR -> { + boolean isMainPart = part == MirrorPart.FOOT_LEFT; + BlockPos[] dependentPositions = (isMainPart ? getAllLargeMirrorPosByMainPos(pCurrentPos, facing) : findLargeMirrorMainPartPositions(pCurrentPos, pState)); + // 统一处理所有关联部件 + boolean flag = canSelfNotSurvive || isAnyCriticalPartMissing(pLevel, dependentPositions); + if (canSelfNotSurvive) { + pLevel.destroyBlock(pCurrentPos, true); + destroyEntireStructure(pLevel, pCurrentPos, dependentPositions); + } else if(isAnyCriticalPartMissing(pLevel, dependentPositions)) { + pLevel.destroyBlock(pCurrentPos, false); + destroyEntireStructure(pLevel, pCurrentPos, dependentPositions); + } + yield flag ? + Blocks.AIR.defaultBlockState() : pState; + } + case MASSIVE_MIRROR -> { + boolean isMainPart = part == MirrorPart.F11; + BlockPos[] dependentPositions = isMainPart ? getAllMassiveMirrorPartsPosByMainPos(pCurrentPos, facing) : findMassiveMirrorMainPartPositions(pCurrentPos, pState); + // 统一处理所有关联部件 + boolean flag = canSelfNotSurvive || isAnyCriticalPartMissing(pLevel, dependentPositions); + if (canSelfNotSurvive) { + pLevel.destroyBlock(pCurrentPos, true); + destroyEntireStructure(pLevel, pCurrentPos, dependentPositions); + } else if(isAnyCriticalPartMissing(pLevel, dependentPositions)) { + pLevel.destroyBlock(pCurrentPos, false); + destroyEntireStructure(pLevel, pCurrentPos, dependentPositions); + } + yield flag ? + Blocks.AIR.defaultBlockState() : pState; + } + }; + } + + @Override + public List getDrops(@NotNull BlockState pState, LootContext.@NotNull Builder pBuilder) { + return super.getDrops(pState, pBuilder); + } + + // 控制实体放置一部分方块后,自动放置另一部分(借鉴于于原版的床放置逻辑) + @Override + public void setPlacedBy(@NotNull Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pState, @Nullable LivingEntity pPlacer, @NotNull ItemStack pStack) { + super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack); + if(!pLevel.isClientSide) { + final Direction facing = pState.getValue(FACING); + switch (mirrorType) { + case COMMON_MIRROR -> { + //NOOP + } + case TELL_MIRROR -> { + BlockPos blockpos = pPos.above(); + pLevel.setBlock(blockpos, pState.setValue(PART, MirrorPart.HEAD), Block.UPDATE_ALL); + pLevel.blockUpdated(pPos, Blocks.AIR); + pState.updateNeighbourShapes(pLevel, pPos, Block.UPDATE_ALL); + } + case LARGE_MIRROR -> { + BlockPos headLeft = pPos.above(), footRight = pPos.relative(facing.getCounterClockWise().getOpposite()), headRight = footRight.above(); + pLevel.setBlock(headLeft, pState.setValue(PART, MirrorPart.HEAD_LEFT), Block.UPDATE_ALL); + pLevel.setBlock(footRight, pState.setValue(PART, MirrorPart.FOOT_RIGHT), Block.UPDATE_ALL); + pLevel.setBlock(headRight, pState.setValue(PART, MirrorPart.HEAD_RIGHT), Block.UPDATE_ALL); + pLevel.blockUpdated(pPos, Blocks.AIR); + pState.updateNeighbourShapes(pLevel, pPos, Block.UPDATE_ALL); + } + case MASSIVE_MIRROR -> { + BlockPos h01 = pPos.above(), + f10 = pPos.relative(facing.getCounterClockWise()), + f12 = pPos.relative(facing.getCounterClockWise().getOpposite()), + h00 = f10.above(), + h02 = f12.above(); + pLevel.setBlock(h00, pState.setValue(PART, MirrorPart.H00), Block.UPDATE_ALL); + pLevel.setBlock(f10, pState.setValue(PART, MirrorPart.F10), Block.UPDATE_ALL); + pLevel.setBlock(h01, pState.setValue(PART, MirrorPart.H01), Block.UPDATE_ALL); + pLevel.setBlock(f12, pState.setValue(PART, MirrorPart.F12), Block.UPDATE_ALL); + pLevel.setBlock(h02, pState.setValue(PART, MirrorPart.H02), Block.UPDATE_ALL); + pLevel.blockUpdated(pPos, Blocks.AIR); + pState.updateNeighbourShapes(pLevel, pPos, Block.UPDATE_ALL); + } + } + } + } + private BlockPos @NotNull [] findMassiveMirrorMainPartPositions(BlockPos currentPos, @NotNull BlockState state) { + Direction facing = state.getValue(FACING); + MirrorPart part = state.getValue(PART); + + // 根据部件类型反向计算主部件位置 + return switch (part) { + case H00 -> getAllMassiveMirrorPartsPosByMainPos(currentPos.relative(facing.getClockWise()).below(), facing); + case H01 -> getAllMassiveMirrorPartsPosByMainPos(currentPos.below(), facing); + case H02 -> getAllMassiveMirrorPartsPosByMainPos(currentPos.relative(facing.getClockWise().getOpposite()).below(),facing); + case F10 -> getAllMassiveMirrorPartsPosByMainPos(currentPos.relative(facing.getClockWise()), facing); + case F12 -> getAllMassiveMirrorPartsPosByMainPos(currentPos.relative(facing.getClockWise().getOpposite()), facing); + default -> throw new IllegalStateException("Unexpected value: " + part); + }; + } + // 辅助方法:获取MASSIVE_MIRROR所有部件坐标 + private BlockPos @NotNull [] getAllMassiveMirrorPartsPosByMainPos(@NotNull BlockPos origin, @NotNull Direction facing) { + BlockPos f10 = origin.relative(facing.getCounterClockWise()); + BlockPos f12 = origin.relative(facing.getCounterClockWise().getOpposite()); + return new BlockPos[]{ + f10, // F10 + f10.above(), // H00 + origin, // F11 + origin.above(), // H01 + f12, // F12 + f12.above() // H02 + }; + } + + // 辅助方法:破坏整个结构 + private void destroyEntireStructure(LevelAccessor level, BlockPos currentPos, BlockPos @NotNull [] parts) { + for (BlockPos pos : parts) { + if (pos.equals(currentPos)) continue; // 跳过当前已处理的方块 + if (level.getBlockState(pos).getBlock() == this) { + level.destroyBlock(pos, false); + } + } + } + + // 辅助方法:检查关键部件是否缺失 + private boolean isAnyCriticalPartMissing(LevelAccessor level, BlockPos @NotNull [] parts) { + for (BlockPos pos : parts) { + if (!level.getBlockState(pos).is(this)) { + return true; + } + } + return false; + } + + /** + * + * @return [0]->FL [1]->HL [2]->FR [3]->HR + */ + private static BlockPos @NotNull [] getAllLargeMirrorPosByMainPos(@NotNull BlockPos pCurrentPos, @NotNull Direction facing) { + BlockPos footRight = pCurrentPos.relative(facing.getCounterClockWise().getOpposite()); + return new BlockPos[]{pCurrentPos, pCurrentPos.above(), footRight, footRight.above()}; + } + + // 用于LARGE_MIRROR反向查找主部件并以此组装有序的数组 + private BlockPos @NotNull [] findLargeMirrorMainPartPositions(BlockPos currentPos, @NotNull BlockState state) { + Direction facing = state.getValue(FACING); + MirrorPart part = state.getValue(PART); + + // 根据部件类型反向计算主部件位置 + return switch (part) { + case HEAD_LEFT -> getAllLargeMirrorPosByMainPos(currentPos.below(), facing); + case FOOT_RIGHT -> getAllLargeMirrorPosByMainPos(currentPos.relative(facing.getClockWise().getOpposite()), facing); + case HEAD_RIGHT -> getAllLargeMirrorPosByMainPos(currentPos.below().relative(facing.getClockWise().getOpposite()),facing); + default -> throw new IllegalStateException("Unexpected value: " + part); }; } @@ -81,7 +327,7 @@ public class MirrorBlock extends HorizontalDirectionalBlock implements EntityBlo return new MirrorBlockEntity(pPos, pState); } - private boolean canAttachTo(BlockGetter pBlockReader, BlockPos pPos, Direction direction) { + private boolean canAttachTo(@NotNull BlockGetter pBlockReader, BlockPos pPos, Direction direction) { BlockState blockState = pBlockReader.getBlockState(pPos); return blockState.isFaceSturdy(pBlockReader, pPos, direction); } @@ -92,46 +338,26 @@ public class MirrorBlock extends HorizontalDirectionalBlock implements EntityBlo return this.canAttachTo(pLevel, pPos.relative(direction), direction); } - - @Override - public @NotNull BlockState updateShape(@NotNull BlockState pState, @NotNull Direction pDirection, @NotNull BlockState pNeighborState, @NotNull LevelAccessor pLevel, @NotNull BlockPos pCurrentPos, @NotNull BlockPos pNeighborPos) { - return switch (mirrorType) { - case COMMON_MIRROR -> (pDirection == pState.getValue(FACING) && !pState.canSurvive(pLevel, pCurrentPos)) ? - Blocks.AIR.defaultBlockState() : super.updateShape(pState, pDirection, pNeighborState, pLevel, pCurrentPos, pNeighborPos); - case TELL_MIRROR -> { - MirrorPart part = pState.getValue(PART); - yield pNeighborState.is(this) && pNeighborState.getValue(PART) != part ? pState : Blocks.AIR.defaultBlockState(); - } - case LARGE_MIRROR -> pLevel.getBlockState(pNeighborPos); - case MASSIVE_MIRROR -> pLevel.getBlockState(pCurrentPos); - }; - } - - @Override - public void setPlacedBy(@NotNull Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pState, @Nullable LivingEntity pPlacer, @NotNull ItemStack pStack) { - super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack); - if(!pLevel.isClientSide) { + public void playerWillDestroy(Level pLevel, BlockPos pPos, BlockState pState, Player pPlayer) { + if (!pLevel.isClientSide ) { + final MirrorPart part = pState.getValue(PART); switch (mirrorType) { case COMMON_MIRROR -> { //NOOP } case TELL_MIRROR -> { - BlockPos blockpos = pPos.above(); - pLevel.setBlock(blockpos, pState.setValue(PART, MirrorPart.HEAD), 3); - pLevel.blockUpdated(pPos, Blocks.AIR); - pState.updateNeighbourShapes(pLevel, pPos, 3); + } case LARGE_MIRROR -> { - BlockPos headLeft = pPos.above(); - pLevel.setBlock(headLeft, pState.setValue(PART, MirrorPart.HEAD_LEFT), 3); - } case MASSIVE_MIRROR -> { } } } + super.playerWillDestroy(pLevel, pPos, pState, pPlayer); } - protected void createBlockStateDefinition(StateDefinition.Builder pBuilder) { + + protected void createBlockStateDefinition(StateDefinition.@NotNull Builder pBuilder) { pBuilder.add(FACING, PART); } } diff --git a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/LargeMirrorShape.java b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/LargeMirrorShape.java index 2efd3ee..cf56c94 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/LargeMirrorShape.java +++ b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/LargeMirrorShape.java @@ -4,8 +4,6 @@ import com.r3944realms.modernlifepatch.content.blocks.type.mirror.MirrorPart; import com.r3944realms.modernlifepatch.utils.ShapeUtil; import net.minecraft.core.Direction; import net.minecraft.world.level.block.Block; -import net.minecraft.world.phys.shapes.BooleanOp; -import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import java.util.stream.Stream; diff --git a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/MassiveMirrorShape.java b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/MassiveMirrorShape.java index c442a53..b663457 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/MassiveMirrorShape.java +++ b/src/main/java/com/r3944realms/modernlifepatch/content/blocks/type/mirror/shape/MassiveMirrorShape.java @@ -5,6 +5,8 @@ import com.r3944realms.modernlifepatch.utils.ShapeUtil; import net.minecraft.core.Direction; import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.util.stream.Stream; @@ -47,7 +49,7 @@ public class MassiveMirrorShape implements IMirrorShape { H02_SHAPE_WEST = ShapeUtil.RotateVoxelShapeClockwise(H02_SHAPE_SOUTH); } @Override - public VoxelShape getDefaultShape(Direction direction) { + public VoxelShape getDefaultShape(@NotNull Direction direction) { return (VoxelShape) switch (direction) { case DOWN, UP -> Stream.empty(); case NORTH -> F11_SHAPE_NORTH; @@ -70,13 +72,14 @@ public class MassiveMirrorShape implements IMirrorShape { default -> throw new IllegalStateException("Unexpected value: " + part); }; } - private VoxelShape N_S_W_E(Direction direction, VoxelShape N, VoxelShape S, VoxelShape E, VoxelShape W) { + @Contract(pure = true) + private VoxelShape N_S_W_E(@NotNull Direction direction, VoxelShape N, VoxelShape S, VoxelShape E, VoxelShape W) { return (VoxelShape) switch (direction) { case DOWN, UP -> Stream.empty(); case NORTH -> N; case SOUTH -> S; - case WEST -> W; - case EAST -> E; + case WEST -> E; + case EAST -> W; }; } diff --git a/src/main/java/com/r3944realms/modernlifepatch/content/items/ModItems.java b/src/main/java/com/r3944realms/modernlifepatch/content/items/ModItems.java index cecaa7c..e882c15 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/content/items/ModItems.java +++ b/src/main/java/com/r3944realms/modernlifepatch/content/items/ModItems.java @@ -14,6 +14,8 @@ public class ModItems { = DeferredRegister.create(ForgeRegistries.ITEMS, ModernLifePatch.MOD_ID); public static final RegistryObject MIRROR_ITEM = ModBlocks.registerBlockItem("mirror", ModBlocks.MIRROR); public static final RegistryObject TALL_MIRROR_ITEM = ModBlocks.registerBlockItem("tall_mirror", ModBlocks.TALL_MIRROR); + public static final RegistryObject LARGE_MIRROR_ITEM = ModBlocks.registerBlockItem("large_mirror", ModBlocks.LARGE_MIRROR); + public static final RegistryObject MASSIVE_MIRROR_ITEM = ModBlocks.registerBlockItem("massive_mirror", ModBlocks.MASSIVE_MIRROR); public static void register(IEventBus bus) { ITEMS.register(bus); } diff --git a/src/main/java/com/r3944realms/modernlifepatch/datagen/DataGeneratorHandler.java b/src/main/java/com/r3944realms/modernlifepatch/datagen/DataGeneratorHandler.java index e96a63a..f049c2c 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/datagen/DataGeneratorHandler.java +++ b/src/main/java/com/r3944realms/modernlifepatch/datagen/DataGeneratorHandler.java @@ -21,6 +21,7 @@ public class DataGeneratorHandler { generator.addProvider(new ModLanguageProvider(generator, LanguageEnum.SimpleChinese)); generator.addProvider(new ModItemModelProvider(generator, existingFileHelper)); generator.addProvider(new ModBlockModelProvider(generator, existingFileHelper)); + generator.addProvider(new ModLootTabProvider(generator)); generator.addProvider(modBlockTagProvider); generator.addProvider(new ModItemTagProvider(generator, modBlockTagProvider, existingFileHelper)); } diff --git a/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModItemModelProvider.java b/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModItemModelProvider.java index 9945c5a..b63e357 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModItemModelProvider.java +++ b/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModItemModelProvider.java @@ -21,6 +21,8 @@ public class ModItemModelProvider extends ItemModelProvider { protected void registerModels() { itemGeneratedModel(ModItems.MIRROR_ITEM.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "item/mirror_item")); itemGeneratedModel(ModItems.TALL_MIRROR_ITEM.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "item/tall_mirror_item")); + itemGeneratedModel(ModItems.LARGE_MIRROR_ITEM.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "item/large_mirror_item")); + itemGeneratedModel(ModItems.MASSIVE_MIRROR_ITEM.get(), new ResourceLocation(ModernLifePatch.MOD_ID, "item/massive_mirror_item")); } public void itemGeneratedModel(Item item, ResourceLocation texture) { diff --git a/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModLootTabProvider.java b/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModLootTabProvider.java new file mode 100644 index 0000000..c2ec7a5 --- /dev/null +++ b/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/ModLootTabProvider.java @@ -0,0 +1,39 @@ +package com.r3944realms.modernlifepatch.datagen.provider; + +import com.google.common.collect.ImmutableList; +import com.mojang.datafixers.util.Pair; +import com.r3944realms.modernlifepatch.datagen.provider.loot.ModBlockLootTables; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.loot.LootTableProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.LootTables; +import net.minecraft.world.level.storage.loot.ValidationContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class ModLootTabProvider extends LootTableProvider { + private final List>>, LootContextParamSet>> + loot_tables = ImmutableList.of(Pair.of(ModBlockLootTables::new, LootContextParamSets.BLOCK)); + + public ModLootTabProvider(DataGenerator pGenerator) { + super(pGenerator); + } + + @Override + protected @NotNull List>>, LootContextParamSet>> getTables() { + return loot_tables; + } + + @Override + protected void validate(@NotNull Map map, @NotNull ValidationContext validationTracker) { + map.forEach((id, table) -> LootTables.validate(validationTracker, id, table)); + } +} diff --git a/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/loot/ModBlockLootTables.java b/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/loot/ModBlockLootTables.java new file mode 100644 index 0000000..48a3c86 --- /dev/null +++ b/src/main/java/com/r3944realms/modernlifepatch/datagen/provider/loot/ModBlockLootTables.java @@ -0,0 +1,22 @@ +package com.r3944realms.modernlifepatch.datagen.provider.loot; + +import com.r3944realms.modernlifepatch.content.blocks.ModBlocks; +import net.minecraft.data.loot.BlockLoot; +import net.minecraft.world.level.block.Block; +import net.minecraftforge.registries.RegistryObject; +import org.jetbrains.annotations.NotNull; + +public class ModBlockLootTables extends BlockLoot { + @Override + protected void addTables() { + this.dropSelf(ModBlocks.MIRROR.get()); + this.dropSelf(ModBlocks.TALL_MIRROR.get()); + this.dropSelf(ModBlocks.LARGE_MIRROR.get()); + this.dropSelf(ModBlocks.MASSIVE_MIRROR.get()); + } + + @Override + protected @NotNull Iterable getKnownBlocks() { + return ModBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator; + } +} diff --git a/src/main/java/com/r3944realms/modernlifepatch/mixin/block/common/MixinSeedSpreader.java b/src/main/java/com/r3944realms/modernlifepatch/mixin/block/common/MixinSeedSpreader.java index 96ae4d5..a7fe1f8 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/mixin/block/common/MixinSeedSpreader.java +++ b/src/main/java/com/r3944realms/modernlifepatch/mixin/block/common/MixinSeedSpreader.java @@ -1,10 +1,7 @@ package com.r3944realms.modernlifepatch.mixin.block.common; import com.dairymoose.modernlife.blocks.SeedSpreaderBlock; -import com.dairymoose.modernlife.blocks.WallSocketBlock; -import com.dairymoose.modernlife.tileentities.RefrigeratorBlockEntity; import com.dairymoose.modernlife.tileentities.SeedSpreaderBlockEntity; -import com.dairymoose.modernlife.util.ModernLifeUtil; import com.r3944realms.modernlifepatch.datagen.lang.ModLangKeyValue; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -27,9 +24,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/src/main/java/com/r3944realms/modernlifepatch/mixin/block/kitchen/MixinRefrigerator.java b/src/main/java/com/r3944realms/modernlifepatch/mixin/block/kitchen/MixinRefrigerator.java index 3da823a..80078b0 100644 --- a/src/main/java/com/r3944realms/modernlifepatch/mixin/block/kitchen/MixinRefrigerator.java +++ b/src/main/java/com/r3944realms/modernlifepatch/mixin/block/kitchen/MixinRefrigerator.java @@ -1,12 +1,10 @@ package com.r3944realms.modernlifepatch.mixin.block.kitchen; import com.dairymoose.modernlife.blocks.RefrigeratorBlock; -import com.dairymoose.modernlife.tileentities.RefrigeratorBlockEntity; import com.dairymoose.modernlife.tileentities.SeedSpreaderBlockEntity; import com.r3944realms.modernlifepatch.datagen.lang.ModLangKeyValue; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.player.Inventory;