Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加激光发射器,棱镜 #836

Merged
merged 32 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a13ef8a
添加管理器
dmzz-yyhyy May 25, 2024
49c0a04
添加光路运算,渲染
dmzz-yyhyy May 31, 2024
ccea78b
Merge branch 'releases/1.20.1' into ruby_laser
dmzz-yyhyy May 31, 2024
17f3d87
添加激光灼烧,激光挖矿
dmzz-yyhyy May 31, 2024
24ddcd8
合并分支,完成灼烧,挖矿功能
dmzz-yyhyy May 31, 2024
0678e4f
Merge branch 'releases/1.20.1' into ruby_laser
dmzz-yyhyy Jun 1, 2024
1c1a1ee
处理合并
dmzz-yyhyy Jun 1, 2024
532180d
修正激光光路传导
dmzz-yyhyy Jun 1, 2024
49d7ad8
修正激光光路传导
dmzz-yyhyy Jun 1, 2024
9af34b8
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 1, 2024
e0de732
修复卡顿问题,修复渲染层问题
dmzz-yyhyy Jun 1, 2024
f20ed9d
增加碰撞检测选项
dmzz-yyhyy Jun 1, 2024
aeea1ce
增加碰撞检测选项
dmzz-yyhyy Jun 1, 2024
3388707
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 1, 2024
b256ddf
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 1, 2024
f6f5bb5
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 1, 2024
683849b
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 1, 2024
d58f462
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
f6ede50
Merge branch 'releases/1.20.1' into ruby_laser
dmzz-yyhyy Jun 2, 2024
c35374e
Merge branch 'releases/1.20.1' into ruby_laser
dmzz-yyhyy Jun 2, 2024
55f962a
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
978afcf
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
83dd861
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
63f5860
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
a336dbd
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
d65dfc7
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 2, 2024
27c3a3e
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 6, 2024
352dc55
Merge branch 'releases/1.20.1' into ruby_laser
dmzz-yyhyy Jun 6, 2024
167d091
Merge branch 'releases/1.20.1' into ruby_laser
dmzz-yyhyy Jun 6, 2024
9d4cec5
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 6, 2024
d3fdc58
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 6, 2024
51fd0a6
Merge remote-tracking branch 'origin/ruby_laser' into ruby_laser
dmzz-yyhyy Jun 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class HudTooltipManager {
static {
INSTANCE.registerTooltip(new PowerComponentTooltipProvider());
INSTANCE.registerAffectRange(new AffectRangeProviderImpl());
INSTANCE.registerTooltip(new RubyPrismTooltipProvider());
}

private void registerAffectRange(AffectRangeProviderImpl affectRangeProvider) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.dubhe.anvilcraft.api.tooltip;

import dev.dubhe.anvilcraft.block.entity.RubyPrismBlockEntity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;

public class RubyPrismTooltipProvider implements TooltipProvider {
RubyPrismTooltipProvider() {}

@Override
public boolean accepts(BlockEntity entity) {
return entity instanceof RubyPrismBlockEntity;
}

@Override
public List<Component> tooltip(BlockEntity e) {
if (!(e instanceof RubyPrismBlockEntity rubyPrismBlockEntity)) return null;
final List<Component> lines = new ArrayList<>();
lines.add(Component.translatable("tooltip.anvilcraft.ruby_prism.power", rubyPrismBlockEntity.laserLevel));
return lines;
}

@Override
public ItemStack icon(BlockEntity entity) {
return entity.getBlockState().getBlock().asItem().getDefaultInstance();
}

@Override
public int priority() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.api.power.IPowerComponent;
import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity;
import dev.dubhe.anvilcraft.block.entity.ItemCollectorBlockEntity;
import dev.dubhe.anvilcraft.init.ModBlockEntities;
import dev.dubhe.anvilcraft.init.ModItems;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.dubhe.anvilcraft.block;

import dev.dubhe.anvilcraft.init.ModBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
Expand Down
125 changes: 125 additions & 0 deletions common/src/main/java/dev/dubhe/anvilcraft/block/RubyLaserBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package dev.dubhe.anvilcraft.block;

import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.api.power.IPowerComponent;
import dev.dubhe.anvilcraft.api.power.IPowerComponent.Switch;
import dev.dubhe.anvilcraft.block.entity.RubyLaserBlockEntity;
import dev.dubhe.anvilcraft.init.ModBlockEntities;
import javax.annotation.Nonnull;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
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.jetbrains.annotations.Nullable;

public class RubyLaserBlock extends BaseEntityBlock implements IHammerRemovable,
IHammerChangeableBlock {
public static final VoxelShape UP_MODEL =
Shapes.or(
Block.box(4, 3, 4, 12, 13, 12),
Block.box(5, 13, 5, 11, 16, 11),
Block.box(3, 0, 3, 13, 3, 13));
public static final VoxelShape DOWN_MODEL =
Shapes.or(
Block.box(4, 3, 4, 12, 13, 12),
Block.box(5, 0, 5, 11, 3, 11),
Block.box(3, 13, 3, 13, 16, 13));
public static final VoxelShape NORTH_MODEL =
Shapes.or(
Block.box(4, 4, 3, 12, 12, 13),
Block.box(5, 5, 0, 11, 11, 3),
Block.box(3, 3, 13, 13, 13, 16));
public static final VoxelShape SOUTH_MODEL =
Shapes.or(
Block.box(4, 4, 3, 12, 12, 13),
Block.box(5, 5, 13, 11, 11, 16),
Block.box(3, 3, 0, 13, 13, 3));
public static final VoxelShape WEST_MODEL =
Shapes.or(
Block.box(3, 4, 4, 13, 12, 12),
Block.box(0, 5, 5, 3, 11, 11),
Block.box(13, 3, 3, 16, 13, 13));
public static final VoxelShape EAST_MODEL =
Shapes.or(
Block.box(3, 4, 4, 13, 12, 12),
Block.box(13, 5, 5, 16, 11, 11),
Block.box(0, 3, 3, 3, 13, 13));
public static final DirectionProperty FACING = DirectionalBlock.FACING;
public static final BooleanProperty OVERLOAD = IPowerComponent.OVERLOAD;
public static final EnumProperty<IPowerComponent.Switch> SWITCH = IPowerComponent.SWITCH;

/**
* 方块状态注册
*/
public RubyLaserBlock(Properties properties) {
super(properties);
this.registerDefaultState(
this.stateDefinition.any()
.setValue(FACING, Direction.DOWN)
.setValue(OVERLOAD, false)
.setValue(SWITCH, Switch.OFF));
}

@Override
protected void createBlockStateDefinition(
@NotNull StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING).add(OVERLOAD).add(SWITCH);
}

@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
return RubyLaserBlockEntity.createBlockEntity(ModBlockEntities.RUBY_LASER.get(), pos, state);
}

@Override
public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos,
@NotNull CollisionContext context) {
return switch (state.getValue(FACING)) {
case UP -> UP_MODEL;
case DOWN -> DOWN_MODEL;
case NORTH -> NORTH_MODEL;
case SOUTH -> SOUTH_MODEL;
case WEST -> WEST_MODEL;
case EAST -> EAST_MODEL;
};
}

@Override
public @Nonnull RenderShape getRenderShape(@Nonnull BlockState state) {
return RenderShape.MODEL;
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection());
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(
@NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> type
) {
if (level.isClientSide) return null;
return createTickerHelper(type, ModBlockEntities.RUBY_LASER.get(),
(level1, pos, state1, entity) -> entity.tick(level1));
}
}
117 changes: 117 additions & 0 deletions common/src/main/java/dev/dubhe/anvilcraft/block/RubyPrismBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package dev.dubhe.anvilcraft.block;

import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.block.entity.RubyPrismBlockEntity;
import dev.dubhe.anvilcraft.init.ModBlockEntities;
import javax.annotation.Nonnull;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
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.jetbrains.annotations.Nullable;

public class RubyPrismBlock extends BaseEntityBlock implements IHammerRemovable,
IHammerChangeableBlock {
public static final VoxelShape UP_MODEL =
Shapes.or(
Block.box(0, 0, 0, 16, 4, 16),
Block.box(2, 4, 2, 14, 14, 14),
Block.box(4, 14, 4, 12, 16, 12));
public static final VoxelShape DOWN_MODEL =
Shapes.or(
Block.box(0, 12, 0, 16, 16, 16),
Block.box(2, 2, 2, 14, 12, 14),
Block.box(4, 0, 4, 12, 2, 12));
public static final VoxelShape NORTH_MODEL =
Shapes.or(
Block.box(0, 0, 12, 16, 16, 16),
Block.box(2, 2, 2, 14, 14, 12),
Block.box(4, 4, 0, 12, 12, 2));
public static final VoxelShape SOUTH_MODEL =
Shapes.or(
Block.box(0, 0, 0, 16, 16, 4),
Block.box(2, 2, 4, 14, 14, 14),
Block.box(4, 4, 14, 12, 12, 16));
public static final VoxelShape WEST_MODEL =
Shapes.or(
Block.box(12, 0, 0, 16, 16, 16),
Block.box(2, 2, 2, 12, 14, 14),
Block.box(0, 4, 4, 2, 12, 12));
public static final VoxelShape EAST_MODEL =
Shapes.or(
Block.box(0, 0, 0, 4, 16, 16),
Block.box(4, 2, 2, 14, 14, 14),
Block.box(14, 4, 4, 16, 12, 12));
public static final DirectionProperty FACING = DirectionalBlock.FACING;

/**
* 方块状态注册
*/
public RubyPrismBlock(Properties properties) {
super(properties);
this.registerDefaultState(
this.stateDefinition.any()
.setValue(FACING, Direction.DOWN));
}

@Override
protected void createBlockStateDefinition(
@NotNull StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
}

@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
return RubyPrismBlockEntity.createBlockEntity(ModBlockEntities.RUBY_PRISM.get(), pos, state);
}

@Override
public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos,
@NotNull CollisionContext context) {
return switch (state.getValue(FACING)) {
case UP -> UP_MODEL;
case DOWN -> DOWN_MODEL;
case NORTH -> NORTH_MODEL;
case SOUTH -> SOUTH_MODEL;
case WEST -> WEST_MODEL;
case EAST -> EAST_MODEL;
};
}

@Override
public @Nonnull RenderShape getRenderShape(@Nonnull BlockState state) {
return RenderShape.MODEL;
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection());
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(
@NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> type
) {
if (level.isClientSide) return null;
return createTickerHelper(type, ModBlockEntities.RUBY_PRISM.get(),
(level1, pos, state1, entity) -> entity.tick(level1));
}
}
Loading
Loading