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 @@ -32,6 +32,7 @@
"anvilcraft_pigsplus.configuration.section.anvilcraft_pigsplus.server.toml": "uoıʇɐɹnbıɟuoƆ ɹǝʌɹǝS snןdsbıԀ ʇɟɐɹɔןıʌuⱯ",
"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.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Ɐ",
"block.anvilcraft_pigsplus.block_breaker": "ɹǝʞɐǝɹᗺ ʞɔoןᗺ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"anvilcraft_pigsplus.configuration.section.anvilcraft_pigsplus.server.toml": "Anvilcraft Pigsplus Server Configuration",
"anvilcraft_pigsplus.configuration.section.anvilcraft_pigsplus.server.toml.title": "Anvilcraft Pigsplus Server Configuration",
"anvilcraft_pigsplus.configuration.title": "Anvilcraft Pigsplus Configuration",
"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",
"block.anvilcraft_pigsplus.block_breaker": "Block Breaker",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "anvilcraft_pigsplus:block/auto_jewel_crafting_table"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_jewelcrafting_table": {
"conditions": {
"items": [
{
"items": "anvilcraft:jewelcrafting_table"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "anvilcraft_pigsplus:auto_jewel_crafting_table"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_jewelcrafting_table"
]
],
"rewards": {
"recipes": [
"anvilcraft_pigsplus:auto_jewel_crafting_table"
]
}
}
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_jewel_crafting_table"
}
],
"rolls": 1.0
}
],
"random_sequence": "anvilcraft_pigsplus:blocks/auto_jewel_crafting_table"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"category": "building",
"key": {
"J": {
"item": "anvilcraft:jewelcrafting_table"
},
"K": {
"item": "anvilcraft_pigsplus:karakuri_component"
},
"M": {
"item": "anvilcraft:magnetoelectric_core"
}
},
"pattern": [
" K ",
" J ",
" M "
],
"result": {
"count": 1,
"id": "anvilcraft_pigsplus:auto_jewel_crafting_table"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"anvilcraft_pigsplus:redstone_conduit_block",
"anvilcraft_pigsplus:block_breaker",
"anvilcraft_pigsplus:chain_smithing_table",
"anvilcraft_pigsplus:auto_jewel_crafting_table",
"anvilcraft_pigsplus:auto_royal_smithing_table",
"anvilcraft_pigsplus:auto_royal_grindstone",
"anvilcraft_pigsplus:chaotic_raw_ore_block",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"values": [
"anvilcraft_pigsplus:chain_smithing_table",
"anvilcraft_pigsplus:auto_jewel_crafting_table",
"anvilcraft_pigsplus:auto_royal_smithing_table",
"anvilcraft_pigsplus:auto_royal_grindstone"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package dev.anvilcraft.pigsplus.block;

import com.mojang.serialization.MapCodec;
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.itemhandler.FilteredItemStackHandler;
import dev.dubhe.anvilcraft.api.power.IPowerComponent;
import dev.dubhe.anvilcraft.block.better.BetterBaseEntityBlock;
import dev.dubhe.anvilcraft.block.entity.BatchCrafterBlockEntity;
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.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 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);
}

@Override
public InteractionResult use(
BlockState state,
Level level,
BlockPos pos,
Player player,
InteractionHand hand,
BlockHitResult hit
) {
if (level.isClientSide) return InteractionResult.SUCCESS;

BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof AutoJewelCraftingTableBlockEntity entity) {
if (player instanceof ServerPlayer serverPlayer) {
if (serverPlayer.gameMode.getGameModeForPlayer() == GameType.SPECTATOR) return InteractionResult.PASS;
AddonMenuTypes.open(serverPlayer, entity, pos);
PacketDistributor.sendToPlayer(serverPlayer, new MachineOutputDirectionPacket(entity.getDirection()));
}
}
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 BatchCrafterBlockEntity entity) {
Vec3 vec3 = entity.getBlockPos().getCenter();
FilteredItemStackHandler 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) {
return null;
}
return createTickerHelper(
type, AddonBlockEntities.AUTO_JEWEL_CRAFTING_TABLE.get(),
(level1, blockPos, blockState, blockEntity) -> blockEntity.tick(level1, blockPos)
);
}
}
Loading