修复部分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
|
98386b2e65b2afb7cf5b0cabf6a7b0f062c1e640 data/superbwarfare/loot_table/blocks/barbed_wire.json
|
||||||
811e69929a14e6736015849c220100bb58d914c9 data/superbwarfare/loot_table/blocks/cemented_carbide_block.json
|
811e69929a14e6736015849c220100bb58d914c9 data/superbwarfare/loot_table/blocks/cemented_carbide_block.json
|
||||||
1f482bc1f0a1026d0e1b75ee28c6f541b56747a5 data/superbwarfare/loot_table/blocks/charging_station.json
|
184c3243ca0acfc3103582e0ada2526b3cb4b43c data/superbwarfare/loot_table/blocks/charging_station.json
|
||||||
088850d9af31c14153b1e837d14d78ea46682ba4 data/superbwarfare/loot_table/blocks/container.json
|
fa8d69f1e943f0a506ae838d0f55c73f1311762f data/superbwarfare/loot_table/blocks/container.json
|
||||||
c7b613c897b0eeca4dbade5eb65f718015dcb853 data/superbwarfare/loot_table/blocks/creative_charging_station.json
|
c7b613c897b0eeca4dbade5eb65f718015dcb853 data/superbwarfare/loot_table/blocks/creative_charging_station.json
|
||||||
f75afc8822e651ec7106271385813e2c6a810866 data/superbwarfare/loot_table/blocks/deepslate_galena_ore.json
|
f75afc8822e651ec7106271385813e2c6a810866 data/superbwarfare/loot_table/blocks/deepslate_galena_ore.json
|
||||||
7e0186c30d572478bebcb62171c1c126801258c2 data/superbwarfare/loot_table/blocks/deepslate_scheelite_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
|
e2fa2e6ba85ec27b3fbb6ad12a731a7ecff1c509 data/superbwarfare/loot_table/blocks/scheelite_ore.json
|
||||||
a223f61202cf9937e8be5b90791925bba09d17b9 data/superbwarfare/loot_table/blocks/silver_block.json
|
a223f61202cf9937e8be5b90791925bba09d17b9 data/superbwarfare/loot_table/blocks/silver_block.json
|
||||||
fb31a40f6a04000f317823cbb80eda8588ba9c69 data/superbwarfare/loot_table/blocks/silver_ore.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
|
83112ebff477e322bd3d23ed4653c7c02b230473 data/superbwarfare/loot_table/blocks/steel_block.json
|
||||||
71fc892124b5343e10688cabc2fb7c87d83cfef8 data/superbwarfare/loot_table/blocks/tungsten_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
|
6e2346c664cd643bff31c0a26e463c6c8dd46e37 data/superbwarfare/loot_table/chests/ancient_cpu.json
|
||||||
031ebfa016c816ebbd03dcf03f169599eed3e9d4 data/superbwarfare/loot_table/chests/blue_print_common.json
|
031ebfa016c816ebbd03dcf03f169599eed3e9d4 data/superbwarfare/loot_table/chests/blue_print_common.json
|
||||||
60f0cf8c558f09fd878a68e0c3a876c9484f83ac data/superbwarfare/loot_table/chests/blue_print_epic.json
|
60f0cf8c558f09fd878a68e0c3a876c9484f83ac data/superbwarfare/loot_table/chests/blue_print_epic.json
|
||||||
|
|
|
@ -16,18 +16,9 @@
|
||||||
],
|
],
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"function": "minecraft:copy_custom_data",
|
"function": "minecraft:copy_components",
|
||||||
"ops": [
|
"include": [
|
||||||
{
|
"superbwarfare:energy"
|
||||||
"op": "replace",
|
|
||||||
"source": "Energy",
|
|
||||||
"target": "BlockEntityTag.Energy"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"op": "replace",
|
|
||||||
"source": "id",
|
|
||||||
"target": "BlockEntityTag.id"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"source": "block_entity"
|
"source": "block_entity"
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,9 @@
|
||||||
],
|
],
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"function": "minecraft:copy_custom_data",
|
"function": "minecraft:copy_components",
|
||||||
"ops": [
|
"include": [
|
||||||
{
|
"minecraft:block_entity_data"
|
||||||
"op": "replace",
|
|
||||||
"source": "Entity",
|
|
||||||
"target": "BlockEntityTag.Entity"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"op": "replace",
|
|
||||||
"source": "EntityType",
|
|
||||||
"target": "BlockEntityTag.EntityType"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"source": "block_entity"
|
"source": "block_entity"
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,9 @@
|
||||||
],
|
],
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"function": "minecraft:copy_custom_data",
|
"function": "minecraft:copy_components",
|
||||||
"ops": [
|
"include": [
|
||||||
{
|
"minecraft:container_loot"
|
||||||
"op": "replace",
|
|
||||||
"source": "LootTable",
|
|
||||||
"target": "BlockEntityTag.LootTable"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"op": "replace",
|
|
||||||
"source": "LootTableSeed",
|
|
||||||
"target": "BlockEntityTag.LootTableSeed"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"source": "block_entity"
|
"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.sounds.SoundSource;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.ItemInteractionResult;
|
import net.minecraft.world.ItemInteractionResult;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
@ -75,7 +74,7 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
return ItemInteractionResult.FAIL;
|
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.setBlockAndUpdate(pos, state.setValue(OPENED, true));
|
||||||
level.playSound(null, BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), ModSounds.OPEN.get(), SoundSource.BLOCKS, 1, 1);
|
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) {
|
public boolean hasEntity(Level level, BlockPos pos) {
|
||||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
if (!(blockEntity instanceof ContainerBlockEntity containerBlockEntity)) return false;
|
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;
|
boolean flag = true;
|
||||||
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
|
@ -103,11 +102,6 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
h = (int) (entityType.getDimensions().height() + 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = -w; i < w + 1; i++) {
|
for (int i = -w; i < w + 1; i++) {
|
||||||
for (int j = 0; j < h; j++) {
|
for (int j = 0; j < h; j++) {
|
||||||
for (int k = -w; k < w + 1; k++) {
|
for (int k = -w; k < w + 1; k++) {
|
||||||
|
@ -193,7 +187,7 @@ public class ContainerBlock extends BaseEntityBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
|
||||||
return simpleCodec(ContainerBlock::new);
|
return simpleCodec(ContainerBlock::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.block.entity;
|
package com.atsuishio.superbwarfare.block.entity;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.ChargingStationBlock;
|
import com.atsuishio.superbwarfare.block.ChargingStationBlock;
|
||||||
|
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
import com.atsuishio.superbwarfare.menu.ChargingStationMenu;
|
||||||
import com.atsuishio.superbwarfare.network.dataslot.ContainerEnergyData;
|
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.Direction;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
|
import net.minecraft.core.component.DataComponentMap;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.IntTag;
|
import net.minecraft.nbt.IntTag;
|
||||||
|
@ -253,6 +255,22 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
||||||
return this.items;
|
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
|
@Override
|
||||||
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
||||||
super.loadAdditional(tag, registries);
|
super.loadAdditional(tag, registries);
|
||||||
|
|
|
@ -5,16 +5,18 @@ import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.HolderLookup;
|
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.particles.ParticleTypes;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.component.CustomData;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
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 class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
|
||||||
|
|
||||||
public EntityType<?> entityType;
|
public EntityType<?> entityType;
|
||||||
public Entity entity = null;
|
public CompoundTag entityTag = null;
|
||||||
public int tick = 0;
|
public int tick = 0;
|
||||||
|
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
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);
|
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 {
|
} else {
|
||||||
if (blockEntity.entity != null) {
|
if (blockEntity.entityTag != 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);
|
var entity = blockEntity.entityType.create(pLevel);
|
||||||
pLevel.addFreshEntity(blockEntity.entity);
|
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) {
|
} else if (blockEntity.entityType != null) {
|
||||||
var entity = blockEntity.entityType.create(pLevel);
|
var entity = blockEntity.entityType.create(pLevel);
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
|
@ -77,7 +83,6 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
|
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
|
||||||
controllers.add(new AnimationController<>(this, "controller", 0, this::predicate));
|
controllers.add(new AnimationController<>(this, "controller", 0, this::predicate));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,33 +90,52 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
||||||
return this.cache;
|
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
|
@Override
|
||||||
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
protected void loadAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
||||||
super.loadAdditional(tag, registries);
|
super.loadAdditional(tag, registries);
|
||||||
|
|
||||||
|
loadFromTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFromTag(CompoundTag tag) {
|
||||||
if (tag.contains("EntityType")) {
|
if (tag.contains("EntityType")) {
|
||||||
this.entityType = EntityType.byString(tag.getString("EntityType")).orElse(null);
|
this.entityType = EntityType.byString(tag.getString("EntityType")).orElse(null);
|
||||||
}
|
}
|
||||||
if (tag.contains("Entity") && this.entityType != null && this.level != null) {
|
if (tag.contains("Entity") && this.entityTag == null && this.entityType != null) {
|
||||||
this.entity = this.entityType.create(this.level);
|
this.entityTag = tag.getCompound("Entity");
|
||||||
if (entity != null) {
|
|
||||||
entity.load(tag.getCompound("Entity"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.tick = tag.getInt("Tick");
|
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
|
@Override
|
||||||
protected void saveAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
protected void saveAdditional(@NotNull CompoundTag tag, HolderLookup.@NotNull Provider registries) {
|
||||||
super.saveAdditional(tag, registries);
|
super.saveAdditional(tag, registries);
|
||||||
|
saveDataToTag(tag);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,8 @@ import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
import net.minecraft.advancements.CriteriaTriggers;
|
import net.minecraft.advancements.CriteriaTriggers;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.HolderLookup;
|
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.particles.ParticleTypes;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
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.entity.player.Player;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.component.SeededContainerLoot;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
@ -98,6 +101,26 @@ public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
||||||
return this.cache;
|
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
|
@Override
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||||
|
|
|
@ -46,17 +46,12 @@ public class ContainerBlockPreview {
|
||||||
|
|
||||||
// 获取实体信息
|
// 获取实体信息
|
||||||
var entityType = container.entityType;
|
var entityType = container.entityType;
|
||||||
var entity = container.entity;
|
|
||||||
|
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
if (entityType != null) {
|
if (entityType != null) {
|
||||||
w = (int) (entityType.getDimensions().width() / 2 + 1);
|
w = (int) (entityType.getDimensions().width() / 2 + 1);
|
||||||
h = (int) (entityType.getDimensions().height() + 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;
|
if (w == 0 || h == 0) return;
|
||||||
|
|
||||||
var poseStack = event.getPoseStack();
|
var poseStack = event.getPoseStack();
|
||||||
|
@ -78,7 +73,7 @@ public class ContainerBlockPreview {
|
||||||
float endY = (float) aabb.maxY + 0.001f - pos.getY();
|
float endY = (float) aabb.maxY + 0.001f - pos.getY();
|
||||||
float endZ = (float) aabb.maxZ + 0.001f - pos.getZ();
|
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 red = hasEnoughSpace ? 0 : 1;
|
||||||
var green = 1 - red;
|
var green = 1 - red;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package com.atsuishio.superbwarfare.client.tooltip;
|
package com.atsuishio.superbwarfare.client.tooltip;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
|
||||||
|
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.item.ChargingStationBlockItem;
|
import com.atsuishio.superbwarfare.item.ChargingStationBlockItem;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.gui.Font;
|
import net.minecraft.client.gui.Font;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
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.Component;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
@ -26,6 +25,7 @@ public class ClientChargingStationImageTooltip implements ClientTooltipComponent
|
||||||
this.height = tooltip.height;
|
this.height = tooltip.height;
|
||||||
this.stack = tooltip.stack;
|
this.stack = tooltip.stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderImage(@NotNull Font font, int x, int y, GuiGraphics guiGraphics) {
|
public void renderImage(@NotNull Font font, int x, int y, GuiGraphics guiGraphics) {
|
||||||
guiGraphics.pose().pushPose();
|
guiGraphics.pose().pushPose();
|
||||||
|
@ -38,9 +38,7 @@ public class ClientChargingStationImageTooltip implements ClientTooltipComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Component getEnergyComponent() {
|
protected Component getEnergyComponent() {
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
int energy = stack.getOrDefault(ModDataComponents.ENERGY.get(), 0);
|
||||||
CompoundTag tag = data != null ? data.copyTag() : new CompoundTag();
|
|
||||||
int energy = tag.getInt("Energy");
|
|
||||||
int maxEnergy = ChargingStationBlockItem.MAX_ENERGY;
|
int maxEnergy = ChargingStationBlockItem.MAX_ENERGY;
|
||||||
float percentage = Mth.clamp((float) energy / maxEnergy, 0, 1);
|
float percentage = Mth.clamp((float) energy / maxEnergy, 0, 1);
|
||||||
MutableComponent component = Component.literal("");
|
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));
|
iTooltip.add(Component.translatable("des.superbwarfare.container.fail.open").withStyle(ChatFormatting.RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
package com.atsuishio.superbwarfare.datagen;
|
package com.atsuishio.superbwarfare.datagen;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||||
import com.atsuishio.superbwarfare.init.ModItems;
|
import com.atsuishio.superbwarfare.init.ModItems;
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import net.minecraft.core.HolderLookup;
|
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.data.loot.BlockLootSubProvider;
|
||||||
import net.minecraft.world.flag.FeatureFlags;
|
import net.minecraft.world.flag.FeatureFlags;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.storage.loot.LootPool;
|
import net.minecraft.world.level.storage.loot.LootPool;
|
||||||
import net.minecraft.world.level.storage.loot.LootTable;
|
import net.minecraft.world.level.storage.loot.LootTable;
|
||||||
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
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.functions.CopyComponentsFunction;
|
||||||
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
|
|
||||||
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -38,10 +39,12 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
||||||
this.dropSelf(ModBlocks.SILVER_BLOCK.get());
|
this.dropSelf(ModBlocks.SILVER_BLOCK.get());
|
||||||
this.dropSelf(ModBlocks.CREATIVE_CHARGING_STATION.get());
|
this.dropSelf(ModBlocks.CREATIVE_CHARGING_STATION.get());
|
||||||
this.dropSelf(ModBlocks.FUMO_25.get());
|
this.dropSelf(ModBlocks.FUMO_25.get());
|
||||||
|
this.dropSelf(ModBlocks.VEHICLE_DEPLOYER.get());
|
||||||
|
|
||||||
this.add(ModBlocks.CHARGING_STATION.get(), createCopyNBTDrops(ModBlocks.CHARGING_STATION.get(),
|
this.add(ModBlocks.CHARGING_STATION.get(), createCopyComponentsDrops(
|
||||||
List.of(Pair.of("Energy", "BlockEntityTag.Energy"),
|
ModBlocks.CHARGING_STATION.get(),
|
||||||
Pair.of("id", "BlockEntityTag.id"))));
|
List.of(ModDataComponents.ENERGY.get()))
|
||||||
|
);
|
||||||
|
|
||||||
this.add(ModBlocks.GALENA_ORE.get(), this.createOreDrop(ModBlocks.GALENA_ORE.get(), ModItems.GALENA.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()));
|
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_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.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(),
|
this.add(ModBlocks.CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(
|
||||||
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.CONTAINER.get()))
|
ModBlocks.CONTAINER.get(),
|
||||||
.apply(CopyCustomDataFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Entity", "BlockEntityTag.Entity")
|
LootPool.lootPool()
|
||||||
.copy("EntityType", "BlockEntityTag.EntityType")))));
|
.setRolls(ConstantValue.exactly(1.0F))
|
||||||
this.add(ModBlocks.SMALL_CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(ModBlocks.SMALL_CONTAINER.get(),
|
.add(LootItem.lootTableItem(ModBlocks.CONTAINER.get()))
|
||||||
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.SMALL_CONTAINER.get()))
|
.apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY)
|
||||||
.apply(CopyCustomDataFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("LootTable", "BlockEntityTag.LootTable")
|
.include(DataComponents.BLOCK_ENTITY_DATA)
|
||||||
.copy("LootTableSeed", "BlockEntityTag.LootTableSeed")))));
|
)
|
||||||
|
)));
|
||||||
|
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
|
@Override
|
||||||
|
@ -65,12 +78,12 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
||||||
return ModBlocks.REGISTRY.getEntries().stream().map(r -> (Block) r.value()).toList();
|
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));
|
var pool = LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(pBlock));
|
||||||
if (!paths.isEmpty()) {
|
if (!components.isEmpty()) {
|
||||||
var copy = CopyCustomDataFunction.copyData(ContextNbtProvider.BLOCK_ENTITY);
|
var copy = CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY);
|
||||||
for (var path : paths) {
|
for (var type : components) {
|
||||||
copy.copy(path.getFirst(), path.getSecond());
|
copy.include(type);
|
||||||
}
|
}
|
||||||
pool.apply(copy);
|
pool.apply(copy);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package com.atsuishio.superbwarfare.item;
|
package com.atsuishio.superbwarfare.item;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.client.tooltip.component.ChargingStationImageComponent;
|
import com.atsuishio.superbwarfare.client.tooltip.component.ChargingStationImageComponent;
|
||||||
|
import com.atsuishio.superbwarfare.component.ModDataComponents;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.core.component.DataComponents;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
@ -26,17 +25,13 @@ public class ChargingStationBlockItem extends BlockItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBarVisible(ItemStack stack) {
|
public boolean isBarVisible(ItemStack stack) {
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
int energy = stack.getOrDefault(ModDataComponents.ENERGY.get(), 0);
|
||||||
CompoundTag tag = data != null ? data.copyTag() : new CompoundTag();
|
|
||||||
int energy = tag.getInt("Energy");
|
|
||||||
return energy != MAX_ENERGY && energy != 0;
|
return energy != MAX_ENERGY && energy != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarWidth(ItemStack stack) {
|
public int getBarWidth(ItemStack stack) {
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
int energy = stack.getOrDefault(ModDataComponents.ENERGY.get(), 0);
|
||||||
CompoundTag tag = data != null ? data.copyTag() : new CompoundTag();
|
|
||||||
int energy = tag.getInt("Energy");
|
|
||||||
return Math.round((float) energy * 13.0F / MAX_ENERGY);
|
return Math.round((float) energy * 13.0F / MAX_ENERGY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResult useOn(UseOnContext context) {
|
public @NotNull InteractionResult useOn(UseOnContext context) {
|
||||||
ItemStack stack = context.getItemInHand();
|
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")) {
|
if (data != null && data.copyTag().getBoolean("CanPlacedAboveWater")) {
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
|
@ -82,7 +82,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) {
|
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) {
|
||||||
ItemStack stack = player.getItemInHand(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")) {
|
if (data != null && data.copyTag().getBoolean("CanPlacedAboveWater")) {
|
||||||
BlockHitResult playerPOVHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.WATER);
|
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) {
|
public static ItemStack createInstance(Entity entity, boolean canPlacedAboveWater) {
|
||||||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
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 tag = data != null ? data.copyTag() : new CompoundTag();
|
||||||
|
|
||||||
var entityTag = 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());
|
tag.putString("EntityType", EntityType.getKey(entity.getType()).toString());
|
||||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||||
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
||||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
stack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createInstance(EntityType<?> entityType, boolean canPlacedAboveWater) {
|
public static ItemStack createInstance(EntityType<?> entityType, boolean canPlacedAboveWater) {
|
||||||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
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 tag = data != null ? data.copyTag() : new CompoundTag();
|
||||||
|
|
||||||
tag.putString("EntityType", EntityType.getKey(entityType).toString());
|
tag.putString("EntityType", EntityType.getKey(entityType).toString());
|
||||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||||
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
||||||
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
stack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue