修复部分BlockEntity挖掘掉落问题
This commit is contained in:
parent
39d012b055
commit
7c27fc02b5
15 changed files with 169 additions and 114 deletions
|
@ -1,8 +1,8 @@
|
|||
// 1.21.1 2025-04-28T03:55:32.0605798 Loot Tables
|
||||
// 1.21.1 2025-05-04T16:53:50.2249137 Loot Tables
|
||||
98386b2e65b2afb7cf5b0cabf6a7b0f062c1e640 data/superbwarfare/loot_table/blocks/barbed_wire.json
|
||||
811e69929a14e6736015849c220100bb58d914c9 data/superbwarfare/loot_table/blocks/cemented_carbide_block.json
|
||||
1f482bc1f0a1026d0e1b75ee28c6f541b56747a5 data/superbwarfare/loot_table/blocks/charging_station.json
|
||||
088850d9af31c14153b1e837d14d78ea46682ba4 data/superbwarfare/loot_table/blocks/container.json
|
||||
184c3243ca0acfc3103582e0ada2526b3cb4b43c data/superbwarfare/loot_table/blocks/charging_station.json
|
||||
fa8d69f1e943f0a506ae838d0f55c73f1311762f data/superbwarfare/loot_table/blocks/container.json
|
||||
c7b613c897b0eeca4dbade5eb65f718015dcb853 data/superbwarfare/loot_table/blocks/creative_charging_station.json
|
||||
f75afc8822e651ec7106271385813e2c6a810866 data/superbwarfare/loot_table/blocks/deepslate_galena_ore.json
|
||||
7e0186c30d572478bebcb62171c1c126801258c2 data/superbwarfare/loot_table/blocks/deepslate_scheelite_ore.json
|
||||
|
@ -17,9 +17,10 @@ ff3548e151685da812f1d5df1dff9fe365b5e0f9 data/superbwarfare/loot_table/blocks/ga
|
|||
e2fa2e6ba85ec27b3fbb6ad12a731a7ecff1c509 data/superbwarfare/loot_table/blocks/scheelite_ore.json
|
||||
a223f61202cf9937e8be5b90791925bba09d17b9 data/superbwarfare/loot_table/blocks/silver_block.json
|
||||
fb31a40f6a04000f317823cbb80eda8588ba9c69 data/superbwarfare/loot_table/blocks/silver_ore.json
|
||||
073b9c242ea372f7b34883835c0b02a9ca8d94e5 data/superbwarfare/loot_table/blocks/small_container.json
|
||||
a0180f3c8988e3564d05bbdd0862c10305ed663e data/superbwarfare/loot_table/blocks/small_container.json
|
||||
83112ebff477e322bd3d23ed4653c7c02b230473 data/superbwarfare/loot_table/blocks/steel_block.json
|
||||
71fc892124b5343e10688cabc2fb7c87d83cfef8 data/superbwarfare/loot_table/blocks/tungsten_block.json
|
||||
5f0de0936df3f782d015d5ee22a224e54c943d5c data/superbwarfare/loot_table/blocks/vehicle_deployer.json
|
||||
6e2346c664cd643bff31c0a26e463c6c8dd46e37 data/superbwarfare/loot_table/chests/ancient_cpu.json
|
||||
031ebfa016c816ebbd03dcf03f169599eed3e9d4 data/superbwarfare/loot_table/chests/blue_print_common.json
|
||||
60f0cf8c558f09fd878a68e0c3a876c9484f83ac data/superbwarfare/loot_table/chests/blue_print_epic.json
|
||||
|
|
|
@ -16,18 +16,9 @@
|
|||
],
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:copy_custom_data",
|
||||
"ops": [
|
||||
{
|
||||
"op": "replace",
|
||||
"source": "Energy",
|
||||
"target": "BlockEntityTag.Energy"
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"source": "id",
|
||||
"target": "BlockEntityTag.id"
|
||||
}
|
||||
"function": "minecraft:copy_components",
|
||||
"include": [
|
||||
"superbwarfare:energy"
|
||||
],
|
||||
"source": "block_entity"
|
||||
}
|
||||
|
|
|
@ -16,18 +16,9 @@
|
|||
],
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:copy_custom_data",
|
||||
"ops": [
|
||||
{
|
||||
"op": "replace",
|
||||
"source": "Entity",
|
||||
"target": "BlockEntityTag.Entity"
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"source": "EntityType",
|
||||
"target": "BlockEntityTag.EntityType"
|
||||
}
|
||||
"function": "minecraft:copy_components",
|
||||
"include": [
|
||||
"minecraft:block_entity_data"
|
||||
],
|
||||
"source": "block_entity"
|
||||
}
|
||||
|
|
|
@ -16,18 +16,9 @@
|
|||
],
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:copy_custom_data",
|
||||
"ops": [
|
||||
{
|
||||
"op": "replace",
|
||||
"source": "LootTable",
|
||||
"target": "BlockEntityTag.LootTable"
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"source": "LootTableSeed",
|
||||
"target": "BlockEntityTag.LootTableSeed"
|
||||
}
|
||||
"function": "minecraft:copy_components",
|
||||
"include": [
|
||||
"minecraft:container_loot"
|
||||
],
|
||||
"source": "block_entity"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"bonus_rolls": 0.0,
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
],
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "superbwarfare:vehicle_deployer"
|
||||
}
|
||||
],
|
||||
"rolls": 1.0
|
||||
}
|
||||
],
|
||||
"random_sequence": "superbwarfare:blocks/vehicle_deployer"
|
||||
}
|
|
@ -14,7 +14,6 @@ import net.minecraft.network.chat.Component;
|
|||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.ItemInteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
@ -75,7 +74,7 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
return ItemInteractionResult.FAIL;
|
||||
}
|
||||
|
||||
if (canOpen(level, pos, containerBlockEntity.entityType, containerBlockEntity.entity)) {
|
||||
if (canOpen(level, pos, containerBlockEntity.entityType)) {
|
||||
level.setBlockAndUpdate(pos, state.setValue(OPENED, true));
|
||||
level.playSound(null, BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), ModSounds.OPEN.get(), SoundSource.BLOCKS, 1, 1);
|
||||
|
||||
|
@ -89,10 +88,10 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
public boolean hasEntity(Level level, BlockPos pos) {
|
||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof ContainerBlockEntity containerBlockEntity)) return false;
|
||||
return containerBlockEntity.entity != null || containerBlockEntity.entityType != null;
|
||||
return containerBlockEntity.entityTag != null || containerBlockEntity.entityType != null;
|
||||
}
|
||||
|
||||
public static boolean canOpen(Level level, BlockPos pos, EntityType<?> entityType, Entity entity) {
|
||||
public static boolean canOpen(Level level, BlockPos pos, EntityType<?> entityType) {
|
||||
boolean flag = true;
|
||||
|
||||
int w = 0;
|
||||
|
@ -103,11 +102,6 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
h = (int) (entityType.getDimensions().height() + 1);
|
||||
}
|
||||
|
||||
if (entity != null) {
|
||||
w = (int) (entity.getType().getDimensions().width() / 2 + 1);
|
||||
h = (int) (entity.getType().getDimensions().height() + 1);
|
||||
}
|
||||
|
||||
for (int i = -w; i < w + 1; i++) {
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int k = -w; k < w + 1; k++) {
|
||||
|
@ -193,7 +187,7 @@ public class ContainerBlock extends BaseEntityBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
||||
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
|
||||
return simpleCodec(ContainerBlock::new);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.block.entity;
|
||||
|
||||
import com.atsuishio.superbwarfare.block.ChargingStationBlock;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
||||
|
@ -8,6 +9,7 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
|
@ -253,6 +255,22 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
|||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyImplicitComponents(@NotNull DataComponentInput componentInput) {
|
||||
super.applyImplicitComponents(componentInput);
|
||||
|
||||
if (this.level != null) {
|
||||
((EnergyStorage) this.energyStorage).deserializeNBT(level.registryAccess(), IntTag.valueOf(componentInput.getOrDefault(ModDataComponents.ENERGY, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectImplicitComponents(DataComponentMap.@NotNull Builder components) {
|
||||
super.collectImplicitComponents(components);
|
||||
|
||||
components.set(ModDataComponents.ENERGY, this.energyStorage.getEnergyStored());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
|
|
|
@ -5,16 +5,18 @@ import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
|||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
@ -29,7 +31,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
|||
public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
|
||||
|
||||
public EntityType<?> entityType;
|
||||
public Entity entity = null;
|
||||
public CompoundTag entityTag = null;
|
||||
public int tick = 0;
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
@ -52,9 +54,13 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
|||
pLevel.playSound(null, pPos, SoundEvents.GENERIC_EXPLODE.value(), SoundSource.BLOCKS, 4.0F, (1.0F + (pLevel.random.nextFloat() - pLevel.random.nextFloat()) * 0.2F) * 0.7F);
|
||||
}
|
||||
} else {
|
||||
if (blockEntity.entity != null) {
|
||||
blockEntity.entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f);
|
||||
pLevel.addFreshEntity(blockEntity.entity);
|
||||
if (blockEntity.entityTag != null) {
|
||||
var entity = blockEntity.entityType.create(pLevel);
|
||||
if (entity != null) {
|
||||
entity.load(blockEntity.entityTag);
|
||||
entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f);
|
||||
pLevel.addFreshEntity(entity);
|
||||
}
|
||||
} else if (blockEntity.entityType != null) {
|
||||
var entity = blockEntity.entityType.create(pLevel);
|
||||
if (entity != null) {
|
||||
|
@ -77,7 +83,6 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
|||
@Override
|
||||
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
|
||||
controllers.add(new AnimationController<>(this, "controller", 0, this::predicate));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,33 +90,52 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
|||
return this.cache;
|
||||
}
|
||||
|
||||
// 保存额外DataComponent以确保正确生成掉落物
|
||||
@Override
|
||||
protected void collectImplicitComponents(DataComponentMap.@NotNull Builder components) {
|
||||
super.collectImplicitComponents(components);
|
||||
|
||||
components.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(saveToTag()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
|
||||
loadFromTag(tag);
|
||||
}
|
||||
|
||||
private void loadFromTag(CompoundTag tag) {
|
||||
if (tag.contains("EntityType")) {
|
||||
this.entityType = EntityType.byString(tag.getString("EntityType")).orElse(null);
|
||||
}
|
||||
if (tag.contains("Entity") && this.entityType != null && this.level != null) {
|
||||
this.entity = this.entityType.create(this.level);
|
||||
if (entity != null) {
|
||||
entity.load(tag.getCompound("Entity"));
|
||||
}
|
||||
if (tag.contains("Entity") && this.entityTag == null && this.entityType != null) {
|
||||
this.entityTag = tag.getCompound("Entity");
|
||||
}
|
||||
this.tick = tag.getInt("Tick");
|
||||
}
|
||||
|
||||
private CompoundTag saveToTag() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString("id", "superbwarfare:container");
|
||||
saveDataToTag(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
private void saveDataToTag(CompoundTag tag) {
|
||||
if (this.entityType != null) {
|
||||
tag.putString("EntityType", EntityType.getKey(this.entityType).toString());
|
||||
}
|
||||
if (this.entityTag != null) {
|
||||
tag.put("Entity", this.entityTag);
|
||||
}
|
||||
tag.putInt("Tick", this.tick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
|
||||
if (this.entity != null) {
|
||||
tag.put("Entity", this.entity.getPersistentData());
|
||||
}
|
||||
if (this.entityType != null) {
|
||||
tag.putString("EntityType", EntityType.getKey(this.entityType).toString());
|
||||
}
|
||||
tag.putInt("Tick", this.tick);
|
||||
saveDataToTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.atsuishio.superbwarfare.tools.ParticleTool;
|
|||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.component.DataComponentMap;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -20,6 +22,7 @@ import net.minecraft.world.entity.item.ItemEntity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.SeededContainerLoot;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
@ -98,6 +101,26 @@ public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||
return this.cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyImplicitComponents(@NotNull DataComponentInput componentInput) {
|
||||
super.applyImplicitComponents(componentInput);
|
||||
|
||||
var loot = componentInput.get(DataComponents.CONTAINER_LOOT);
|
||||
if (loot != null) {
|
||||
this.lootTable = loot.lootTable();
|
||||
this.lootTableSeed = loot.seed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectImplicitComponents(DataComponentMap.@NotNull Builder components) {
|
||||
super.collectImplicitComponents(components);
|
||||
|
||||
if (this.lootTable != null) {
|
||||
components.set(DataComponents.CONTAINER_LOOT, new SeededContainerLoot(this.lootTable, this.lootTableSeed));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
|
|
|
@ -46,17 +46,12 @@ public class ContainerBlockPreview {
|
|||
|
||||
// 获取实体信息
|
||||
var entityType = container.entityType;
|
||||
var entity = container.entity;
|
||||
|
||||
int w = 0, h = 0;
|
||||
if (entityType != null) {
|
||||
w = (int) (entityType.getDimensions().width() / 2 + 1);
|
||||
h = (int) (entityType.getDimensions().height() + 1);
|
||||
}
|
||||
if (entity != null) {
|
||||
w = (int) (entity.getType().getDimensions().width() / 2 + 1);
|
||||
h = (int) (entity.getType().getDimensions().height() + 1);
|
||||
}
|
||||
if (w == 0 || h == 0) return;
|
||||
|
||||
var poseStack = event.getPoseStack();
|
||||
|
@ -78,7 +73,7 @@ public class ContainerBlockPreview {
|
|||
float endY = (float) aabb.maxY + 0.001f - pos.getY();
|
||||
float endZ = (float) aabb.maxZ + 0.001f - pos.getZ();
|
||||
|
||||
var hasEnoughSpace = ContainerBlock.canOpen(level, pos, entityType, entity);
|
||||
var hasEnoughSpace = ContainerBlock.canOpen(level, pos, entityType);
|
||||
|
||||
var red = hasEnoughSpace ? 0 : 1;
|
||||
var green = 1 - red;
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package com.atsuishio.superbwarfare.client.tooltip;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.item.ChargingStationBlockItem;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -26,6 +25,7 @@ public class ClientChargingStationImageTooltip implements ClientTooltipComponent
|
|||
this.height = tooltip.height;
|
||||
this.stack = tooltip.stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderImage(@NotNull Font font, int x, int y, GuiGraphics guiGraphics) {
|
||||
guiGraphics.pose().pushPose();
|
||||
|
@ -38,9 +38,7 @@ public class ClientChargingStationImageTooltip implements ClientTooltipComponent
|
|||
}
|
||||
|
||||
protected Component getEnergyComponent() {
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
CompoundTag tag = data != null ? data.copyTag() : new CompoundTag();
|
||||
int energy = tag.getInt("Energy");
|
||||
int energy = stack.getOrDefault(ModDataComponents.ENERGY.get(), 0);
|
||||
int maxEnergy = ChargingStationBlockItem.MAX_ENERGY;
|
||||
float percentage = Mth.clamp((float) energy / maxEnergy, 0, 1);
|
||||
MutableComponent component = Component.literal("");
|
||||
|
|
|
@ -37,7 +37,7 @@ public enum ContainerEntityProvider implements IBlockComponentProvider {
|
|||
}
|
||||
|
||||
// 空间不足提示
|
||||
if (!ContainerBlock.canOpen(blockAccessor.getLevel(), container.getBlockPos(), container.entityType, container.entity)) {
|
||||
if (!ContainerBlock.canOpen(blockAccessor.getLevel(), container.getBlockPos(), container.entityType)) {
|
||||
iTooltip.add(Component.translatable("des.superbwarfare.container.fail.open").withStyle(ChatFormatting.RED));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package com.atsuishio.superbwarfare.datagen;
|
||||
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.data.loot.BlockLootSubProvider;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.storage.loot.LootPool;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
||||
import net.minecraft.world.level.storage.loot.functions.CopyCustomDataFunction;
|
||||
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
|
||||
import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction;
|
||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -38,10 +39,12 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
|||
this.dropSelf(ModBlocks.SILVER_BLOCK.get());
|
||||
this.dropSelf(ModBlocks.CREATIVE_CHARGING_STATION.get());
|
||||
this.dropSelf(ModBlocks.FUMO_25.get());
|
||||
this.dropSelf(ModBlocks.VEHICLE_DEPLOYER.get());
|
||||
|
||||
this.add(ModBlocks.CHARGING_STATION.get(), createCopyNBTDrops(ModBlocks.CHARGING_STATION.get(),
|
||||
List.of(Pair.of("Energy", "BlockEntityTag.Energy"),
|
||||
Pair.of("id", "BlockEntityTag.id"))));
|
||||
this.add(ModBlocks.CHARGING_STATION.get(), createCopyComponentsDrops(
|
||||
ModBlocks.CHARGING_STATION.get(),
|
||||
List.of(ModDataComponents.ENERGY.get()))
|
||||
);
|
||||
|
||||
this.add(ModBlocks.GALENA_ORE.get(), this.createOreDrop(ModBlocks.GALENA_ORE.get(), ModItems.GALENA.get()));
|
||||
this.add(ModBlocks.SCHEELITE_ORE.get(), this.createOreDrop(ModBlocks.SCHEELITE_ORE.get(), ModItems.SCHEELITE.get()));
|
||||
|
@ -50,14 +53,24 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
|||
this.add(ModBlocks.DEEPSLATE_SCHEELITE_ORE.get(), this.createOreDrop(ModBlocks.DEEPSLATE_SCHEELITE_ORE.get(), ModItems.SCHEELITE.get()));
|
||||
this.add(ModBlocks.DEEPSLATE_SILVER_ORE.get(), this.createOreDrop(ModBlocks.DEEPSLATE_SILVER_ORE.get(), ModItems.RAW_SILVER.get()));
|
||||
|
||||
this.add(ModBlocks.CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(ModBlocks.CONTAINER.get(),
|
||||
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.CONTAINER.get()))
|
||||
.apply(CopyCustomDataFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Entity", "BlockEntityTag.Entity")
|
||||
.copy("EntityType", "BlockEntityTag.EntityType")))));
|
||||
this.add(ModBlocks.SMALL_CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(ModBlocks.SMALL_CONTAINER.get(),
|
||||
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.SMALL_CONTAINER.get()))
|
||||
.apply(CopyCustomDataFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("LootTable", "BlockEntityTag.LootTable")
|
||||
.copy("LootTableSeed", "BlockEntityTag.LootTableSeed")))));
|
||||
this.add(ModBlocks.CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(
|
||||
ModBlocks.CONTAINER.get(),
|
||||
LootPool.lootPool()
|
||||
.setRolls(ConstantValue.exactly(1.0F))
|
||||
.add(LootItem.lootTableItem(ModBlocks.CONTAINER.get()))
|
||||
.apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY)
|
||||
.include(DataComponents.BLOCK_ENTITY_DATA)
|
||||
)
|
||||
)));
|
||||
this.add(ModBlocks.SMALL_CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(
|
||||
ModBlocks.SMALL_CONTAINER.get(),
|
||||
LootPool.lootPool()
|
||||
.setRolls(ConstantValue.exactly(1.0F))
|
||||
.add(LootItem.lootTableItem(ModBlocks.SMALL_CONTAINER.get()))
|
||||
.apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY)
|
||||
.include(DataComponents.CONTAINER_LOOT)
|
||||
)
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,12 +78,12 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
|||
return ModBlocks.REGISTRY.getEntries().stream().map(r -> (Block) r.value()).toList();
|
||||
}
|
||||
|
||||
public LootTable.Builder createCopyNBTDrops(Block pBlock, List<Pair<String, String>> paths) {
|
||||
public LootTable.Builder createCopyComponentsDrops(Block pBlock, List<DataComponentType<?>> components) {
|
||||
var pool = LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(pBlock));
|
||||
if (!paths.isEmpty()) {
|
||||
var copy = CopyCustomDataFunction.copyData(ContextNbtProvider.BLOCK_ENTITY);
|
||||
for (var path : paths) {
|
||||
copy.copy(path.getFirst(), path.getSecond());
|
||||
if (!components.isEmpty()) {
|
||||
var copy = CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY);
|
||||
for (var type : components) {
|
||||
copy.include(type);
|
||||
}
|
||||
pool.apply(copy);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.ChargingStationImageComponent;
|
||||
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
|
@ -26,17 +25,13 @@ public class ChargingStationBlockItem extends BlockItem {
|
|||
|
||||
@Override
|
||||
public boolean isBarVisible(ItemStack stack) {
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
CompoundTag tag = data != null ? data.copyTag() : new CompoundTag();
|
||||
int energy = tag.getInt("Energy");
|
||||
int energy = stack.getOrDefault(ModDataComponents.ENERGY.get(), 0);
|
||||
return energy != MAX_ENERGY && energy != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBarWidth(ItemStack stack) {
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
CompoundTag tag = data != null ? data.copyTag() : new CompoundTag();
|
||||
int energy = tag.getInt("Energy");
|
||||
int energy = stack.getOrDefault(ModDataComponents.ENERGY.get(), 0);
|
||||
return Math.round((float) energy * 13.0F / MAX_ENERGY);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
@Override
|
||||
public @NotNull InteractionResult useOn(UseOnContext context) {
|
||||
ItemStack stack = context.getItemInHand();
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
|
||||
if (data != null && data.copyTag().getBoolean("CanPlacedAboveWater")) {
|
||||
return InteractionResult.PASS;
|
||||
|
@ -82,7 +82,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
@Override
|
||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
|
||||
if (data != null && data.copyTag().getBoolean("CanPlacedAboveWater")) {
|
||||
BlockHitResult playerPOVHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.WATER);
|
||||
|
@ -156,7 +156,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
public static ItemStack createInstance(Entity entity, boolean canPlacedAboveWater) {
|
||||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
var tag = data != null ? data.copyTag() : new CompoundTag();
|
||||
|
||||
var entityTag = new CompoundTag();
|
||||
|
@ -170,20 +170,20 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
|||
tag.putString("EntityType", EntityType.getKey(entity.getType()).toString());
|
||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
||||
stack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack createInstance(EntityType<?> entityType, boolean canPlacedAboveWater) {
|
||||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||
var data = stack.get(DataComponents.CUSTOM_DATA);
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
var tag = data != null ? data.copyTag() : new CompoundTag();
|
||||
|
||||
tag.putString("EntityType", EntityType.getKey(entityType).toString());
|
||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
||||
stack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue