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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"anvilcraft_pigsplus.configuration.section.anvilcraft_pigsplus.server.toml.title": "uoıʇɐɹnbıɟuoƆ ɹǝʌɹǝS snןdsbıԀ ʇɟɐɹɔןıʌuⱯ",
"anvilcraft_pigsplus.configuration.title": "uoıʇɐɹnbıɟuoƆ snןdsbıԀ ʇɟɐɹɔןıʌuⱯ",
"block.anvilcraft_pigsplus.adjustable_power_converter": "ɹǝʇɹǝʌuoƆ ɹǝʍoԀ ǝןqɐʇsnظpⱯ",
"block.anvilcraft_pigsplus.auto_chicken": "uǝʞɔıɥƆ oʇnⱯ",
"block.anvilcraft_pigsplus.auto_jewel_crafting_table": "ǝןqɐ⟘ buıʇɟɐɹƆ ןǝʍǝſ oʇnⱯ",
"block.anvilcraft_pigsplus.auto_royal_grindstone": "ǝuoʇspuıɹ⅁ ןɐʎoᴚ oʇnⱯ",
"block.anvilcraft_pigsplus.auto_royal_smithing_table": "ǝןqɐ⟘ buıɥʇıɯS ןɐʎoᴚ oʇnⱯ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"anvilcraft_pigsplus.configuration.section.anvilcraft_pigsplus.server.toml.title": "Anvilcraft Pigsplus Server Configuration",
"anvilcraft_pigsplus.configuration.title": "Anvilcraft Pigsplus Configuration",
"block.anvilcraft_pigsplus.adjustable_power_converter": "Adjustable Power Converter",
"block.anvilcraft_pigsplus.auto_chicken": "Auto Chicken",
"block.anvilcraft_pigsplus.auto_jewel_crafting_table": "Auto Jewel Crafting Table",
"block.anvilcraft_pigsplus.auto_royal_grindstone": "Auto Royal Grindstone",
"block.anvilcraft_pigsplus.auto_royal_smithing_table": "Auto Royal Smithing Table",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "anvilcraft_pigsplus:block/auto_chicken"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_the_recipe": {
"conditions": {
"recipe": "anvilcraft:item_compress/auto_chicken"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"anvilcraft:item_compress/auto_chicken"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "anvilcraft:item_compress",
"ingredients": [
{
"count": 2,
"items": "anvilcraft_pigsplus:karakuri_component"
},
{
"items": "anvilcraft:resin_block",
"predicates": {
"anvilcraft:saved_entity": {
"entitys": "minecraft:chicken"
}
}
}
],
"results": [
{
"id": "anvilcraft_pigsplus:auto_chicken"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "anvilcraft_pigsplus:auto_chicken"
}
],
"rolls": 1.0
}
],
"random_sequence": "anvilcraft_pigsplus:blocks/auto_chicken"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"values": [
"anvilcraft_pigsplus:cauldron_output",
"anvilcraft_pigsplus:auto_chicken",
"anvilcraft_pigsplus:redstone_conduit_block",
"anvilcraft_pigsplus:block_breaker",
"anvilcraft_pigsplus:chain_smithing_table",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.anvilcraft.pigsplus.anvil;

import dev.anvilcraft.pigsplus.block.AutoChickenBlock;
import dev.dubhe.anvilcraft.api.anvil.IAnvilBehavior;
import dev.dubhe.anvilcraft.api.event.AnvilEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public class AutoChickenBehavior implements IAnvilBehavior {
@Override
public boolean handle(Level level, BlockPos hitBlockPos, BlockState hitBlockState, float fallDistance, AnvilEvent.OnLand event) {
if (!(level instanceof ServerLevel serverLevel)) return false;

AutoChickenBlock block = (AutoChickenBlock) hitBlockState.getBlock();
block.spawnEgg(serverLevel, hitBlockPos, fallDistance);
return true;
}
}
103 changes: 103 additions & 0 deletions src/main/java/dev/anvilcraft/pigsplus/block/AutoChickenBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package dev.anvilcraft.pigsplus.block;

import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.item.ItemEntity;
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.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

public class AutoChickenBlock extends Block implements IHammerRemovable {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

public static VoxelShape SHAPE = Shapes.or(
Block.box(0, 14, 0, 16, 16, 16),
Block.box(2, 2, 2, 14, 14, 14),
Block.box(0, 0, 0, 16, 2, 16)
);

public AutoChickenBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition
.any()
.setValue(FACING, Direction.NORTH));
}

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

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

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

@Override
public VoxelShape getShape(
BlockState state,
BlockGetter level,
BlockPos pos,
CollisionContext context
) {
return SHAPE;
}

public void spawnEgg(ServerLevel level, BlockPos pos, float fallDistance) {
BlockState breakerBlockState = level.getBlockState(pos);
if (breakerBlockState.isAir()) return;
RandomSource randomSource = level.getRandom();
float f = randomSource.nextFloat();
if (fallDistance <= 1.25f) {
fallDistance = 1.25f;
}
if (f <= (1 / fallDistance)) {
return;
}
// 在方块下方生成一个鸡蛋掉落物
ItemStack itemStack = new ItemStack(Items.EGG);
Vec3 itemPos = pos.below().getCenter();
level.addFreshEntity(
new ItemEntity(
level,
itemPos.x,
itemPos.y,
itemPos.z,
itemStack,
level.random.nextDouble() * 0.2 - 0.1,
-0.5,
level.random.nextDouble() * 0.2 - 0.1
)
);
// 产生鸡下蛋的声音
level.playSound(
null,
pos,
SoundEvents.CHICKEN_EGG,
SoundSource.BLOCKS,
0.7F,
level.random.nextFloat() * 0.2F + 0.9F
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,34 @@
import dev.anvilcraft.pigsplus.block.entity.AutoJewelCraftingTableBlockEntity;
import dev.anvilcraft.pigsplus.init.AddonBlockEntities;
import dev.anvilcraft.pigsplus.init.AddonMenuTypes;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.api.power.IPowerComponent;
import dev.dubhe.anvilcraft.block.better.BetterBaseEntityBlock;
import dev.dubhe.anvilcraft.network.MachineOutputDirectionPacket;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.GameType;
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.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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.Nullable;

public class AutoJewelCraftingTableBlock extends BetterBaseEntityBlock implements IHammerRemovable {
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
public static final BooleanProperty OVERLOAD = IPowerComponent.OVERLOAD;
public class AutoJewelCraftingTableBlock extends AutoMachineBlock {

public AutoJewelCraftingTableBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition
.any()
.setValue(POWERED, false)
.setValue(OVERLOAD, true));
}

@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return simpleCodec(AutoJewelCraftingTableBlock::new);
}

@Override
public boolean hasAnalogOutputSignal(BlockState blockState) {
return true;
}

@Override
public int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos blockPos) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);
if (blockEntity instanceof AutoJewelCraftingTableBlockEntity autoJewelCraftingTableBlockEntity) {
return autoJewelCraftingTableBlockEntity.getRedstoneSignal();
}
return 0;
}

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

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new AutoJewelCraftingTableBlockEntity(AddonBlockEntities.AUTO_JEWEL_CRAFTING_TABLE.get(), pos, state);
Expand Down Expand Up @@ -99,67 +59,6 @@ public InteractionResult use(
return InteractionResult.SUCCESS;
}


@Override
public void onRemove(
BlockState state,
Level level,
BlockPos pos,
BlockState newState,
boolean movedByPiston
) {
if (state.is(newState.getBlock())) return;
if (level.getBlockEntity(pos) instanceof AutoJewelCraftingTableBlockEntity entity) {
Vec3 vec3 = entity.getBlockPos().getCenter();
IItemHandler itemHandler = entity.getItemHandler();
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
Containers.dropItemStack(level, vec3.x, vec3.y, vec3.z, itemHandler.getStackInSlot(slot));
}
level.updateNeighbourForOutputSignal(pos, this);
}
super.onRemove(state, level, pos, newState, movedByPiston);
}


@Nullable
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState()
.setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()))
.setValue(OVERLOAD, true);
}

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

@Override
public void neighborChanged(
BlockState state,
Level level,
BlockPos pos,
Block neighborBlock,
BlockPos neighborPos,
boolean movedByPiston
) {
if (level.isClientSide) {
return;
}
level.setBlock(pos, state.setValue(POWERED, level.hasNeighborSignal(pos)), 2);
}

@Override
public void tick(
BlockState state,
ServerLevel level,
BlockPos pos,
RandomSource random
) {
if (state.getValue(POWERED) && !level.hasNeighborSignal(pos)) {
level.setBlock(pos, state.cycle(POWERED), 2);
}
}

@Override
public @Nullable <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
if (level.isClientSide) {
Expand Down
Loading