Skip to content

Commit 9aec043

Browse files
同步
1 parent 3c436e1 commit 9aec043

21 files changed

Lines changed: 619 additions & 1862 deletions

build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ neoForge {
5252

5353
configureEach {
5454
systemProperty 'forge.logging.markers', 'REGISTRIES'
55-
5655
logLevel = org.slf4j.event.Level.DEBUG
56+
57+
jvmArguments.addAll([
58+
// 忽略无效指令,避免有的人没安装 JetBrain Runtime 无法启动游戏
59+
"-XX:+IgnoreUnrecognizedVMOptions",
60+
// 启用 JetBrain Runtime 热重载功能
61+
"-XX:+AllowEnhancedClassRedefinition"
62+
])
5763
}
5864
}
5965

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ loader_version_range=[1,)
1515
## Mod Properties
1616
mod_id=futurefood
1717
mod_name=Future Food
18-
mod_license=All Rights Reserved
18+
mod_license=MIT
1919
mod_version=1.0.0
2020
mod_group_id=top.ctnstudio.futurefood
2121
mod_authors=

src/main/java/top/ctnstudio/futurefood/FutureFood.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
1111
import top.ctnstudio.futurefood.init.ModBlock;
12+
import top.ctnstudio.futurefood.init.ModCreativeModeTab;
13+
import top.ctnstudio.futurefood.init.ModItem;
1214
import top.ctnstudio.futurefood.init.ModTileEntity;
1315

1416
import javax.annotation.CheckForNull;
@@ -53,5 +55,7 @@ public static <T> T getModObject(final Registry<T> registry, final String name)
5355
private void register(final RegisterEvent event) {
5456
ModBlock.init(event);
5557
ModTileEntity.init(event);
58+
ModItem.init(event);
59+
ModCreativeModeTab.init(event);
5660
}
5761
}

src/main/java/top/ctnstudio/futurefood/client/gui/tool/blit_nine_sliced/SliceSprite.java renamed to src/main/java/top/ctnstudio/futurefood/client/gui/tool/blitninesliced/SliceSprite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package top.ctnstudio.futurefood.client.gui.tool.blit_nine_sliced;
1+
package top.ctnstudio.futurefood.client.gui.tool.blitninesliced;
22

33
import net.minecraft.client.gui.GuiGraphics;
44
import net.minecraft.resources.ResourceLocation;

src/main/java/top/ctnstudio/futurefood/client/gui/tool/blit_nine_sliced/SliceSpriteData.java renamed to src/main/java/top/ctnstudio/futurefood/client/gui/tool/blitninesliced/SliceSpriteData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package top.ctnstudio.futurefood.client.gui.tool.blit_nine_sliced;
1+
package top.ctnstudio.futurefood.client.gui.tool.blitninesliced;
22

33
/// 切片精灵数据
44
public final class SliceSpriteData {

src/main/java/top/ctnstudio/futurefood/client/gui/tool/blit_nine_sliced/SliceSpriteSliceData.java renamed to src/main/java/top/ctnstudio/futurefood/client/gui/tool/blitninesliced/SliceSpriteSliceData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package top.ctnstudio.futurefood.client.gui.tool.blit_nine_sliced;
1+
package top.ctnstudio.futurefood.client.gui.tool.blitninesliced;
22

33
import net.minecraft.client.gui.GuiGraphics;
44
import net.minecraft.resources.ResourceLocation;
@@ -15,4 +15,3 @@ public void blit(ResourceLocation texture, GuiGraphics guiGraphics, int x, int y
1515
guiGraphics.blit(texture, x, y, width, height, uOffset, vOffset, uWidth, vHeight, textureWidth, textureHeight);
1616
}
1717
}
18-

src/main/java/top/ctnstudio/futurefood/client/gui/tool/blit_nine_sliced/SliceSpriteSliceDataBuilder.java renamed to src/main/java/top/ctnstudio/futurefood/client/gui/tool/blitninesliced/SliceSpriteSliceDataBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package top.ctnstudio.futurefood.client.gui.tool.blit_nine_sliced;
1+
package top.ctnstudio.futurefood.client.gui.tool.blitninesliced;
22

33
public class SliceSpriteSliceDataBuilder {
44
// 使用 ThreadLocal 缓存 builder 实例
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package top.ctnstudio.futurefood.common.block;
2+
3+
import net.minecraft.core.Direction;
4+
import net.minecraft.world.item.context.BlockPlaceContext;
5+
import net.minecraft.world.level.block.BaseEntityBlock;
6+
import net.minecraft.world.level.block.Block;
7+
import net.minecraft.world.level.block.Mirror;
8+
import net.minecraft.world.level.block.Rotation;
9+
import net.minecraft.world.level.block.state.BlockState;
10+
import net.minecraft.world.level.block.state.StateDefinition;
11+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
12+
import net.minecraft.world.level.block.state.properties.DirectionProperty;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
public abstract class DirectionalEntityBlock extends BaseEntityBlock {
16+
protected static final DirectionProperty FACING = BlockStateProperties.FACING;
17+
protected DirectionalEntityBlock(Properties properties) {
18+
super(properties);
19+
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
20+
}
21+
22+
@Override
23+
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
24+
builder.add(FACING);
25+
}
26+
27+
/**
28+
* 放置时调用
29+
*/
30+
@Override
31+
public BlockState getStateForPlacement(BlockPlaceContext context) {
32+
return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection().getOpposite());
33+
}
34+
35+
/**
36+
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed blockstate.
37+
*/
38+
@Override
39+
protected @NotNull BlockState rotate(BlockState state, Rotation rot) {
40+
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
41+
}
42+
43+
/**
44+
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed blockstate.
45+
*/
46+
@Override
47+
protected @NotNull BlockState mirror(BlockState state, Mirror mirror) {
48+
return state.rotate(mirror.getRotation(state.getValue(FACING)));
49+
}
50+
}

src/main/java/top/ctnstudio/futurefood/common/block/QedEntityBlock.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.serialization.MapCodec;
44
import net.minecraft.core.BlockPos;
5+
import net.minecraft.world.item.context.BlockPlaceContext;
56
import net.minecraft.world.level.BlockGetter;
67
import net.minecraft.world.level.block.BaseEntityBlock;
78
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -14,8 +15,7 @@
1415

1516
import javax.annotation.Nullable;
1617

17-
public class QedEntityBlock extends BaseEntityBlock {
18-
public static final VoxelShape SHAPE = makeShape();
18+
public class QedEntityBlock extends DirectionalEntityBlock {
1919
private static final MapCodec<QedEntityBlock> CODEC = simpleCodec(QedEntityBlock::new);
2020

2121
public QedEntityBlock() {
@@ -26,19 +26,6 @@ private QedEntityBlock(Properties properties) {
2626
super(properties);
2727
}
2828

29-
@SuppressWarnings("DuplicatedCode")
30-
private static VoxelShape makeShape() {
31-
VoxelShape shape = Shapes.empty();
32-
shape = Shapes.join(shape, Shapes.box(0.25, -0.0015625000000000083, 0.25, 0.75, 0.125, 0.75), BooleanOp.OR);
33-
shape = Shapes.join(shape, Shapes.box(0.25, 0, 0.25, 0.75, 0.25, 0.75), BooleanOp.OR);
34-
shape = Shapes.join(shape, Shapes.box(0.25, 0.8125, 0.25, 0.75, 0.875, 0.75), BooleanOp.OR);
35-
shape = Shapes.join(shape, Shapes.box(0.375, 0.625, 0.375, 0.625, 0.6875, 0.625), BooleanOp.OR);
36-
shape = Shapes.join(shape, Shapes.box(0.375, 0.125, 0.375, 0.625, 0.4375, 0.625), BooleanOp.OR);
37-
shape = Shapes.join(shape, Shapes.box(0.4375, 0.4375, 0.4375, 0.5625, 1.1875, 0.5625), BooleanOp.OR);
38-
shape = Shapes.join(shape, Shapes.box(0.375, 1, 0.375, 0.625, 1.0625, 0.625), BooleanOp.OR);
39-
return shape;
40-
}
41-
4229
@Override
4330
protected MapCodec<? extends BaseEntityBlock> codec() {
4431
return CODEC;
@@ -51,7 +38,7 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
5138
}
5239

5340
@Override
54-
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
55-
return SHAPE;
41+
public BlockState getStateForPlacement(BlockPlaceContext context) {
42+
return this.defaultBlockState().setValue(FACING, context.getClickedFace());
5643
}
5744
}

src/main/java/top/ctnstudio/futurefood/common/block/QerEntityBlock.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.serialization.MapCodec;
44
import net.minecraft.core.BlockPos;
5+
import net.minecraft.world.item.context.BlockPlaceContext;
56
import net.minecraft.world.level.BlockGetter;
67
import net.minecraft.world.level.block.BaseEntityBlock;
78
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -15,8 +16,7 @@
1516

1617
import javax.annotation.Nullable;
1718

18-
public class QerEntityBlock extends BaseEntityBlock {
19-
public static final VoxelShape SHAPE = makeShape();
19+
public class QerEntityBlock extends DirectionalEntityBlock {
2020
private static final MapCodec<QerEntityBlock> CODEC = simpleCodec(QerEntityBlock::new);
2121

2222
public QerEntityBlock() {
@@ -27,27 +27,6 @@ private QerEntityBlock(Properties properties) {
2727
super(properties);
2828
}
2929

30-
@SuppressWarnings("DuplicatedCode")
31-
private static VoxelShape makeShape() {
32-
VoxelShape shape = Shapes.empty();
33-
shape = Shapes.join(shape, Shapes.box(0.25, -0.0015625000000000083, 0.25, 0.75, 0.125, 0.75), BooleanOp.OR);
34-
shape = Shapes.join(shape, Shapes.box(0.25, 0, 0.25, 0.75, 0.25, 0.75), BooleanOp.OR);
35-
shape = Shapes.join(shape, Shapes.box(-0.004441738241592191, -0.125, 0.3124999999999999, 0.05805826175840764, 0.3125, 0.5625), BooleanOp.OR);
36-
shape = Shapes.join(shape, Shapes.box(0.9419417382415922, -0.125, 0.4375, 1.0044417382415922, 0.3125, 0.6875000000000001), BooleanOp.OR);
37-
shape = Shapes.join(shape, Shapes.box(0.9419417382415922, -0.125, 0.3125, 1.0044417382415922, 0.3125, 0.5625000000000001), BooleanOp.OR);
38-
shape = Shapes.join(shape, Shapes.box(0.3124999999999999, -0.125, 0.9419417382415922, 0.5625, 0.3125, 1.0044417382415922), BooleanOp.OR);
39-
shape = Shapes.join(shape, Shapes.box(0.12055826175840781, 0.3125, 0.3749999999999999, 0.18305826175840764, 0.6875, 0.625), BooleanOp.OR);
40-
shape = Shapes.join(shape, Shapes.box(0.3749999999999999, 0.3125, 0.8169417382415923, 0.625, 0.6875, 0.8794417382415922), BooleanOp.OR);
41-
shape = Shapes.join(shape, Shapes.box(0.375, 0.3125, 0.12055826175840778, 0.6250000000000001, 0.6875, 0.18305826175840767), BooleanOp.OR);
42-
shape = Shapes.join(shape, Shapes.box(0.8169417382415923, 0.3125, 0.375, 0.8794417382415922, 0.6875, 0.6250000000000001), BooleanOp.OR);
43-
shape = Shapes.join(shape, Shapes.box(0.25, 0.8125, 0.25, 0.75, 0.875, 0.75), BooleanOp.OR);
44-
shape = Shapes.join(shape, Shapes.box(0.375, 0.625, 0.375, 0.625, 0.6875, 0.625), BooleanOp.OR);
45-
shape = Shapes.join(shape, Shapes.box(0.375, 0.125, 0.375, 0.625, 0.4375, 0.625), BooleanOp.OR);
46-
shape = Shapes.join(shape, Shapes.box(0.4375, 0.4375, 0.4375, 0.5625, 1.1875, 0.5625), BooleanOp.OR);
47-
shape = Shapes.join(shape, Shapes.box(0.375, 1, 0.375, 0.625, 1.0625, 0.625), BooleanOp.OR);
48-
return shape;
49-
}
50-
5130
@Override
5231
protected MapCodec<? extends BaseEntityBlock> codec() {
5332
return CODEC;
@@ -60,7 +39,7 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
6039
}
6140

6241
@Override
63-
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
64-
return SHAPE;
42+
public BlockState getStateForPlacement(BlockPlaceContext context) {
43+
return this.defaultBlockState().setValue(FACING, context.getClickedFace());
6544
}
6645
}

0 commit comments

Comments
 (0)