show itemhoarder content
This commit is contained in:
parent
83682ce03d
commit
26f529f672
@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
loader_version=0.10.6+build.214
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.16.4.2
|
||||
mod_version = 1.16.4.3
|
||||
maven_group = de.jottyfan.minecraft
|
||||
archives_base_name = quickiefabric
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.blockentity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -8,11 +9,16 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -121,4 +127,23 @@ public class ItemHoarderBlockEntity extends LootableContainerBlockEntity impleme
|
||||
protected Text getContainerName() {
|
||||
return new TranslatableText("container.itemhoarder");
|
||||
}
|
||||
|
||||
/**
|
||||
* get a summary of content for the chat box
|
||||
*
|
||||
* @return the summary
|
||||
*/
|
||||
public List<Text> getSummary() {
|
||||
List<Text> list = new ArrayList<>();
|
||||
for (ItemStack stack : stacks) {
|
||||
Item item = stack.getItem();
|
||||
if (item != Items.AIR) {
|
||||
Integer amount = stack.getCount();
|
||||
Text text = new LiteralText(String.format("%dx ", amount))
|
||||
.append(new TranslatableText(stack.getTranslationKey())).setStyle(Style.EMPTY.withColor(Formatting.GOLD));
|
||||
list.add(text);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.blockentity.ItemHoarderBlockEntity;
|
||||
@ -13,7 +15,14 @@ import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext.Builder;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemScatterer;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
@ -52,4 +61,21 @@ public class BlockItemhoarder extends Block implements BlockEntityProvider {
|
||||
}
|
||||
super.onBreak(world, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
|
||||
BlockHitResult hit) {
|
||||
if (!world.isClient) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof ItemHoarderBlockEntity) {
|
||||
ItemHoarderBlockEntity ihbe = (ItemHoarderBlockEntity) blockEntity;
|
||||
player.sendMessage(new TranslatableText("msg.itemhoarder.summary",
|
||||
new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date())).setStyle(Style.EMPTY.withColor(Formatting.BOLD)), false);
|
||||
for (Text text : ihbe.getSummary()) {
|
||||
player.sendMessage(text, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user