修复小集装箱的显示问题
This commit is contained in:
parent
366cf0a668
commit
a66d34468c
3 changed files with 7 additions and 16 deletions
|
@ -212,7 +212,6 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(OPENED, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) {
|
||||
|
@ -220,6 +219,5 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
level.getBlockEntity(pos, ModBlockEntities.CONTAINER.get()).ifPresent((blockEntity) -> blockEntity.saveToItem(itemStack, level.registryAccess()));
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.minecraft.ChatFormatting;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
@ -90,10 +89,9 @@ public class SmallContainerBlock extends BaseEntityBlock {
|
|||
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
CompoundTag tag = data != null ? data.copyTag() : null;
|
||||
if (tag != null) {
|
||||
String lootTable = tag.getString("LootTable");
|
||||
var data = stack.get(DataComponents.CONTAINER_LOOT);
|
||||
if (data != null) {
|
||||
String lootTable = data.lootTable().location().toString();
|
||||
if (lootTable.startsWith(Mod.MODID + ":containers/")) {
|
||||
var split = lootTable.split(Mod.MODID + ":containers/");
|
||||
if (split.length == 2) {
|
||||
|
@ -101,7 +99,7 @@ public class SmallContainerBlock extends BaseEntityBlock {
|
|||
}
|
||||
tooltipComponents.add(Component.translatable("des.superbwarfare.small_container." + lootTable).withStyle(ChatFormatting.GRAY));
|
||||
} else {
|
||||
long seed = tag.getLong("LootTableSeed");
|
||||
long seed = data.seed();
|
||||
if (seed != 0 && seed % 205 == 0) {
|
||||
tooltipComponents.add(Component.translatable("des.superbwarfare.small_container.special").withStyle(ChatFormatting.GRAY));
|
||||
} else {
|
||||
|
|
|
@ -2,16 +2,16 @@ package com.atsuishio.superbwarfare.item;
|
|||
|
||||
import com.atsuishio.superbwarfare.Mod;
|
||||
import com.atsuishio.superbwarfare.client.renderer.item.SmallContainerBlockItemRenderer;
|
||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.SeededContainerLoot;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
|
@ -77,12 +77,7 @@ public class SmallContainerBlockItem extends BlockItem implements GeoItem {
|
|||
|
||||
public static ItemStack createInstance(ResourceKey<LootTable> lootTable, long lootTableSeed) {
|
||||
ItemStack stack = new ItemStack(ModBlocks.SMALL_CONTAINER.get());
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString("LootTable", lootTable.location().toString());
|
||||
if (lootTableSeed != 0L) {
|
||||
tag.putLong("LootTableSeed", lootTableSeed);
|
||||
}
|
||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.SMALL_CONTAINER.get(), tag);
|
||||
stack.set(DataComponents.CONTAINER_LOOT, new SeededContainerLoot(lootTable, lootTableSeed));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue