Update to 1.4.1

MirrorBlock中updateShape方法里一堆烂代码,别看
This commit is contained in:
叁玖领域 2025-02-08 02:07:11 +08:00
parent a6f28f47c1
commit bc8614dedd
21 changed files with 442 additions and 53 deletions

View File

@ -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
mod.version = 1.18.2-1.4.1

View File

@ -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

View File

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "modernlifepatch:item/large_mirror_item"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "modernlifepatch:item/massive_mirror_item"
}
}

View File

@ -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"
}
]
}
]
}

View File

@ -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"
}
]
}
]
}

View File

@ -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"
}
]
}
]
}

View File

@ -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"
}
]
}
]
}

View File

@ -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());

View File

@ -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 {

View File

@ -21,6 +21,10 @@ public class ModBlocks {
() -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.COMMON_MIRROR));
public static final RegistryObject<MirrorBlock> TALL_MIRROR = BLOCKS.register("tall_mirror",
() -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.TELL_MIRROR));
public static final RegistryObject<MirrorBlock> LARGE_MIRROR= BLOCKS.register("large_mirror",
() -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.LARGE_MIRROR));
public static final RegistryObject<MirrorBlock> MASSIVE_MIRROR = BLOCKS.register("massive_mirror" ,
() -> new MirrorBlock(BlockBehaviour.Properties.copy(Blocks.GLASS), MirrorPart.MirrorType.MASSIVE_MIRROR));
@SuppressWarnings("UnusedReturnValue")
public static <T extends Block> RegistryObject<BlockItem> registerBlockItem(String name , RegistryObject<T> block){
return ModItems.ITEMS.register(name,() -> new BlockItem(block.get(),new Item.Properties()));

View File

@ -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<MirrorPart> 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<ItemStack> 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<Block, BlockState> pBuilder) {
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> pBuilder) {
pBuilder.add(FACING, PART);
}
}

View File

@ -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;

View File

@ -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;
};
}

View File

@ -14,6 +14,8 @@ public class ModItems {
= DeferredRegister.create(ForgeRegistries.ITEMS, ModernLifePatch.MOD_ID);
public static final RegistryObject<BlockItem> MIRROR_ITEM = ModBlocks.registerBlockItem("mirror", ModBlocks.MIRROR);
public static final RegistryObject<BlockItem> TALL_MIRROR_ITEM = ModBlocks.registerBlockItem("tall_mirror", ModBlocks.TALL_MIRROR);
public static final RegistryObject<BlockItem> LARGE_MIRROR_ITEM = ModBlocks.registerBlockItem("large_mirror", ModBlocks.LARGE_MIRROR);
public static final RegistryObject<BlockItem> MASSIVE_MIRROR_ITEM = ModBlocks.registerBlockItem("massive_mirror", ModBlocks.MASSIVE_MIRROR);
public static void register(IEventBus bus) {
ITEMS.register(bus);
}

View File

@ -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));
}

View File

@ -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) {

View File

@ -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<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>>
loot_tables = ImmutableList.of(Pair.of(ModBlockLootTables::new, LootContextParamSets.BLOCK));
public ModLootTabProvider(DataGenerator pGenerator) {
super(pGenerator);
}
@Override
protected @NotNull List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
return loot_tables;
}
@Override
protected void validate(@NotNull Map<ResourceLocation, LootTable> map, @NotNull ValidationContext validationTracker) {
map.forEach((id, table) -> LootTables.validate(validationTracker, id, table));
}
}

View File

@ -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<Block> getKnownBlocks() {
return ModBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get)::iterator;
}
}

View File

@ -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;

View File

@ -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;