info about items in itemhoarder started
This commit is contained in:
@@ -7,8 +7,12 @@ import org.jspecify.annotations.Nullable;
|
||||
|
||||
import de.jottyfan.minecraft.blockentity.ItemHoarderBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -18,6 +22,7 @@ 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.storage.loot.LootParams.Builder;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -47,9 +52,31 @@ public class Itemhoarder extends Block implements EntityBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> getDrops(BlockState state, Builder params) {
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player,
|
||||
BlockHitResult hitResult) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof ItemHoarderBlockEntity) {
|
||||
ItemHoarderBlockEntity ihbe = (ItemHoarderBlockEntity) blockEntity;
|
||||
for (ItemStack stack : ihbe.getStacks().values()) {
|
||||
buf.append(stack.getCount()).append("x ").append(stack.getItemName()); // itemName is not the translated version...
|
||||
buf.append("\n"); // doesn't work that way
|
||||
}
|
||||
}
|
||||
|
||||
Component message = Component.translatable("info.block.itemhoarder", buf.toString());
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.displayClientMessage(message, true);
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> getDrops(BlockState state, Builder builder) {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(QuicklyBlocks.ITEMHOARDER));
|
||||
|
||||
// TODO: add content of spawnAfterBreak here?
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"info.block.itemhoarder": "enthält %s",
|
||||
"info.block.monsterhoarder": "Radius: %s, Brenndauer: %s Ticks",
|
||||
"item.quickly.blockcanolaplant": "Rapspflanze",
|
||||
"item.quickly.blockcottonplant": "Baumwollpflanze",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"info.block.itemhoarder": "keeps %s",
|
||||
"info.block.monsterhoarder": "radius: %s, burn ticks: %s",
|
||||
"item.quickly.blockcanolaplant": "canola plant",
|
||||
"item.quickly.blockcottonplant": "cotton plant",
|
||||
|
||||
Reference in New Issue
Block a user