Skip to content

Commit

Permalink
fix: 重命名并修改同步内容
Browse files Browse the repository at this point in the history
  • Loading branch information
skyinr committed Aug 9, 2023
1 parent 36b910f commit 8208e93
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package games.moegirl.sinocraft.sinofeast.block;

import games.moegirl.sinocraft.sinocore.block.AbstractEntityBlock;
import games.moegirl.sinocraft.sinofeast.block.entity.CoppingBoardBlockEntity;
import games.moegirl.sinocraft.sinofeast.block.entity.ChoppingBoardBlockEntity;
import games.moegirl.sinocraft.sinofeast.block.entity.SFBlockEntities;
import games.moegirl.sinocraft.sinofeast.item.SFItems;
import games.moegirl.sinocraft.sinofeast.utility.IFood;
Expand All @@ -22,11 +22,11 @@
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.items.IItemHandler;

public class CoppingBoardBlock extends AbstractEntityBlock<CoppingBoardBlockEntity> {
public class ChoppingBoardBlock extends AbstractEntityBlock<ChoppingBoardBlockEntity> {
public static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 2, 14);

public CoppingBoardBlock() {
super(Properties.of(), SFBlockEntities.COPPING_BOARD_BLOCK_ENTITY);
public ChoppingBoardBlock() {
super(Properties.of(), SFBlockEntities.CHOPPING_BOARD_BLOCK_ENTITY);
}

@Override
Expand All @@ -40,34 +40,34 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
if (hand == InteractionHand.MAIN_HAND) {

ItemStack itemInHand = player.getItemInHand(hand);
if (state.getBlock() instanceof CoppingBoardBlock coppingBoardBlock) {
CoppingBoardBlockEntity blockEntity = coppingBoardBlock.getBlockEntity(level, pos);
if (state.getBlock() instanceof ChoppingBoardBlock choppingBoardBlock) {
ChoppingBoardBlockEntity blockEntity = choppingBoardBlock.getBlockEntity(level, pos);
IItemHandler iItemHandler = blockEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).orElseThrow(RuntimeException::new);
ItemStack inFood = iItemHandler.getStackInSlot(CoppingBoardBlockEntity.INPUT);
ItemStack inFood = iItemHandler.getStackInSlot(ChoppingBoardBlockEntity.INPUT);
if (itemInHand.is(SFItems.KITCHEN_KNIFE.get())) {

ItemStack copy = inFood.copy();
inFood.setCount(inFood.getCount() - 1);
copy.setCount(1);
copy.addTagElement("shred", ByteTag.valueOf(true));
iItemHandler.insertItem(CoppingBoardBlockEntity.OUTPUT, copy, false);
iItemHandler.insertItem(ChoppingBoardBlockEntity.OUTPUT, copy, false);

} else if (itemInHand.isEmpty()) {
if (player.isShiftKeyDown()) {
ItemStack outItem = iItemHandler.extractItem(CoppingBoardBlockEntity.OUTPUT, 64, false);
ItemStack outItem = iItemHandler.extractItem(ChoppingBoardBlockEntity.OUTPUT, 64, false);
if (!outItem.isEmpty()) {
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY() + 0.5, pos.getZ(), outItem));
}
} else {
ItemStack inItem = iItemHandler.extractItem(CoppingBoardBlockEntity.INPUT, 64, false);
ItemStack inItem = iItemHandler.extractItem(ChoppingBoardBlockEntity.INPUT, 64, false);
if (!inItem.isEmpty()) {
level.addFreshEntity(new ItemEntity(level, pos.getX(), pos.getY() + 0.5, pos.getZ(), inItem));
}
}


} else if (itemInHand.getItem() instanceof IFood){
player.setItemInHand(hand, iItemHandler.insertItem(CoppingBoardBlockEntity.INPUT, itemInHand, false));
player.setItemInHand(hand, iItemHandler.insertItem(ChoppingBoardBlockEntity.INPUT, itemInHand, false));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static void register(IEventBus bus) {
.addItem(TEA_TREE);

TabsRegistry.items(SinoSeriesTabs.FUNCTIONAL_BLOCKS)
.addItem(COPPING_BOARD);
.addItem(CHOPPING_BOARD);
}

public static final RegistryObject<BlockItem> TEA_TREE = BLOCK_ITEMS.register("tea_tree", () -> new ItemNameBlockItem(SFBlocks.TEA_TREE_BLOCK.get(), new Item.Properties()));
public static final RegistryObject<BlockItem> COPPING_BOARD = BLOCK_ITEMS.register("copping_board", () -> new ItemNameBlockItem(SFBlocks.COPPING_BOARD_BLOCK.get(), new Item.Properties()));
public static final RegistryObject<BlockItem> CHOPPING_BOARD = BLOCK_ITEMS.register("chopping_board", () -> new ItemNameBlockItem(SFBlocks.CHOPPING_BOARD_BLOCK.get(), new Item.Properties()));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public static void register(IEventBus bus) {

public static final RegistryObject<Block> TEA_TREE_BLOCK = BLOCKS.register("tea_tree", TeaTreeBlock::new);

public static final RegistryObject<Block> COPPING_BOARD_BLOCK = BLOCKS.register("copping_board", CoppingBoardBlock::new);
public static final RegistryObject<Block> CHOPPING_BOARD_BLOCK = BLOCKS.register("chopping_board", ChoppingBoardBlock::new);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CoppingBoardBlockEntity extends BlockEntity {
public class ChoppingBoardBlockEntity extends BlockEntity {
public static final int INPUT = 0;
public static final int OUTPUT = 1;
private LazyOptional<IItemHandler> foodHandler;
public static final String FOOD = "food";
public CoppingBoardBlockEntity(BlockPos arg2, BlockState arg3) {
super(SFBlockEntities.COPPING_BOARD_BLOCK_ENTITY.get(), arg2, arg3);
public static final String INPUT_FOOD = "input_food";
public static final String OUTPUT_FOOD = "output_food";
public ChoppingBoardBlockEntity(BlockPos arg2, BlockState arg3) {
super(SFBlockEntities.CHOPPING_BOARD_BLOCK_ENTITY.get(), arg2, arg3);
}

@Override
public void handleUpdateTag(CompoundTag tag) {
super.handleUpdateTag(tag);
var food = getCapability(ForgeCapabilities.ITEM_HANDLER).orElseThrow(RuntimeException::new);
deserializeCaps(tag);
food.insertItem(0, ItemStack.of(tag.getCompound(FOOD)),false);
food.insertItem(INPUT, ItemStack.of(tag.getCompound(INPUT_FOOD)),false);
food.insertItem(OUTPUT,ItemStack.of(tag.getCompound(OUTPUT_FOOD)),false);
}

@NotNull
@Override
public CompoundTag getUpdateTag() {
CompoundTag tag = super.getUpdateTag();
var food = getCapability(ForgeCapabilities.ITEM_HANDLER).orElseThrow(RuntimeException::new);
invalidateCaps();
tag.put(FOOD, food.getStackInSlot(0).serializeNBT());

tag.put(INPUT_FOOD, food.getStackInSlot(INPUT).serializeNBT());
tag.put(OUTPUT_FOOD,food.getStackInSlot(OUTPUT).serializeNBT());
return tag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public static void register(IEventBus bus) {

public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, SinoFeast.MODID);

public static final Supplier<BlockEntityType<CoppingBoardBlockEntity>> COPPING_BOARD_BLOCK_ENTITY = BLOCK_ENTITIES.register("copping_board", () ->
public static final Supplier<BlockEntityType<ChoppingBoardBlockEntity>> CHOPPING_BOARD_BLOCK_ENTITY = BLOCK_ENTITIES.register("chopping_board", () ->
BlockEntityType
.Builder
.of(CoppingBoardBlockEntity::new,
SFBlocks.COPPING_BOARD_BLOCK.get()).build(null));
.of(ChoppingBoardBlockEntity::new,
SFBlocks.CHOPPING_BOARD_BLOCK.get()).build(null));


}

0 comments on commit 8208e93

Please sign in to comment.