添加blockitem的nbt
This commit is contained in:
parent
652dec04c8
commit
1008a673ce
8 changed files with 65 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
||||||
// 1.20.1 2024-11-28T19:06:08.9130891 Loot Tables
|
// 1.20.1 2024-11-28T19:45:16.1283469 Loot Tables
|
||||||
98386b2e65b2afb7cf5b0cabf6a7b0f062c1e640 data/superbwarfare/loot_tables/blocks/barbed_wire.json
|
98386b2e65b2afb7cf5b0cabf6a7b0f062c1e640 data/superbwarfare/loot_tables/blocks/barbed_wire.json
|
||||||
811e69929a14e6736015849c220100bb58d914c9 data/superbwarfare/loot_tables/blocks/cemented_carbide_block.json
|
811e69929a14e6736015849c220100bb58d914c9 data/superbwarfare/loot_tables/blocks/cemented_carbide_block.json
|
||||||
92190e844ccc6a9e63e4c063ee3a0932f722156a data/superbwarfare/loot_tables/blocks/container.json
|
8ed3f1d518c86fe6ed14f14f3121c2e24e109269 data/superbwarfare/loot_tables/blocks/container.json
|
||||||
dabbe17417c944567dc6dfcdcba32b8377c24f69 data/superbwarfare/loot_tables/blocks/deepslate_galena_ore.json
|
dabbe17417c944567dc6dfcdcba32b8377c24f69 data/superbwarfare/loot_tables/blocks/deepslate_galena_ore.json
|
||||||
a7c1af3e194d35a64544902468bd964f45f2f9ef data/superbwarfare/loot_tables/blocks/deepslate_scheelite_ore.json
|
a7c1af3e194d35a64544902468bd964f45f2f9ef data/superbwarfare/loot_tables/blocks/deepslate_scheelite_ore.json
|
||||||
76fa64ff714374c1655f4d11776fda132287a014 data/superbwarfare/loot_tables/blocks/deepslate_silver_ore.json
|
76fa64ff714374c1655f4d11776fda132287a014 data/superbwarfare/loot_tables/blocks/deepslate_silver_ore.json
|
||||||
|
|
|
@ -20,8 +20,13 @@
|
||||||
"ops": [
|
"ops": [
|
||||||
{
|
{
|
||||||
"op": "replace",
|
"op": "replace",
|
||||||
"source": "Test",
|
"source": "Entity",
|
||||||
"target": "BlockEntityTag.Test"
|
"target": "BlockEntityTag.Entity"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"op": "replace",
|
||||||
|
"source": "EntityType",
|
||||||
|
"target": "BlockEntityTag.EntityType"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": "block_entity"
|
"source": "block_entity"
|
||||||
|
|
|
@ -24,7 +24,7 @@ import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class ContainerBlock extends BaseEntityBlock implements SimpleWaterloggedBlock, EntityBlock {
|
public class ContainerBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||||
public static final BooleanProperty OPENED = BooleanProperty.create("opened");
|
public static final BooleanProperty OPENED = BooleanProperty.create("opened");
|
||||||
|
@ -35,12 +35,15 @@ public class ContainerBlock extends BaseEntityBlock implements SimpleWaterlogged
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack pStack, @org.jetbrains.annotations.Nullable BlockGetter pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
|
public void appendHoverText(ItemStack pStack, @Nullable BlockGetter pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
|
||||||
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
|
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
|
||||||
CompoundTag compoundtag = BlockItem.getBlockEntityData(pStack);
|
CompoundTag compoundtag = BlockItem.getBlockEntityData(pStack);
|
||||||
if (compoundtag != null) {
|
if (compoundtag != null) {
|
||||||
if (compoundtag.contains("Test")) {
|
if (compoundtag.contains("Entity")) {
|
||||||
pTooltip.add(Component.literal("Test: " + compoundtag.getInt("Test")));
|
pTooltip.add(Component.literal("Entity: " + compoundtag.getString("Entity")));
|
||||||
|
}
|
||||||
|
if (compoundtag.contains("EntityType")) {
|
||||||
|
pTooltip.add(Component.literal("EntityType: " + compoundtag.getString("EntityType")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
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.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import software.bernie.geckolib.animatable.GeoBlockEntity;
|
import software.bernie.geckolib.animatable.GeoBlockEntity;
|
||||||
|
@ -17,7 +19,8 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
|
public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
|
||||||
|
|
||||||
public int test = 0;
|
public EntityType<?> entityType;
|
||||||
|
public Entity entity = null;
|
||||||
|
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
|
|
||||||
|
@ -42,13 +45,23 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void load(CompoundTag compound) {
|
public void load(CompoundTag compound) {
|
||||||
super.load(compound);
|
super.load(compound);
|
||||||
this.test = compound.getInt("Test");
|
if (compound.contains("Entity")) {
|
||||||
|
entity.deserializeNBT(compound.getCompound("Entity"));
|
||||||
|
}
|
||||||
|
if (compound.contains("EntityType")) {
|
||||||
|
this.entityType = EntityType.byString(compound.getString("EntityType")).orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAdditional(CompoundTag compound) {
|
public void saveAdditional(CompoundTag compound) {
|
||||||
super.saveAdditional(compound);
|
super.saveAdditional(compound);
|
||||||
compound.putInt("Test", this.test);
|
if (this.entity != null) {
|
||||||
|
compound.put("Entity", this.entity.serializeNBT());
|
||||||
|
}
|
||||||
|
if (this.entityType != null) {
|
||||||
|
compound.putString("EntityType", EntityType.getKey(this.entityType).toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,7 +43,8 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
||||||
|
|
||||||
this.add(ModBlocks.CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(ModBlocks.CONTAINER.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()))
|
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.CONTAINER.get()))
|
||||||
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Test", "BlockEntityTag.Test")))));
|
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Entity", "BlockEntityTag.Entity")
|
||||||
|
.copy("EntityType", "BlockEntityTag.EntityType")))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,6 +12,7 @@ import javax.annotation.Nullable;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class ModBlockTagProvider extends BlockTagsProvider {
|
public class ModBlockTagProvider extends BlockTagsProvider {
|
||||||
|
|
||||||
public ModBlockTagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, @Nullable ExistingFileHelper existingFileHelper) {
|
public ModBlockTagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, @Nullable ExistingFileHelper existingFileHelper) {
|
||||||
super(output, lookupProvider, ModUtils.MODID, existingFileHelper);
|
super(output, lookupProvider, ModUtils.MODID, existingFileHelper);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +30,5 @@ public class ModBlockTagProvider extends BlockTagsProvider {
|
||||||
ModBlocks.CEMENTED_CARBIDE_BLOCK.get(), ModBlocks.SILVER_ORE.get(), ModBlocks.DEEPSLATE_SILVER_ORE.get(),
|
ModBlocks.CEMENTED_CARBIDE_BLOCK.get(), ModBlocks.SILVER_ORE.get(), ModBlocks.DEEPSLATE_SILVER_ORE.get(),
|
||||||
ModBlocks.SILVER_BLOCK.get(), ModBlocks.JUMP_PAD.get(), ModBlocks.CONTAINER.get());
|
ModBlocks.SILVER_BLOCK.get(), ModBlocks.JUMP_PAD.get(), ModBlocks.CONTAINER.get());
|
||||||
this.tag(BlockTags.MINEABLE_WITH_SHOVEL).add(ModBlocks.SANDBAG.get());
|
this.tag(BlockTags.MINEABLE_WITH_SHOVEL).add(ModBlocks.SANDBAG.get());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.init;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.item.ArmorPlate;
|
import com.atsuishio.superbwarfare.item.ArmorPlate;
|
||||||
|
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
|
||||||
import com.atsuishio.superbwarfare.item.gun.handgun.Glock17Item;
|
import com.atsuishio.superbwarfare.item.gun.handgun.Glock17Item;
|
||||||
import com.atsuishio.superbwarfare.item.gun.handgun.Glock18Item;
|
import com.atsuishio.superbwarfare.item.gun.handgun.Glock18Item;
|
||||||
import com.atsuishio.superbwarfare.item.gun.handgun.M1911Item;
|
import com.atsuishio.superbwarfare.item.gun.handgun.M1911Item;
|
||||||
|
@ -105,7 +106,9 @@ public class ModTabs {
|
||||||
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
|
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
|
||||||
output.accept(ArmorPlate.getInfiniteInstance());
|
output.accept(ArmorPlate.getInfiniteInstance());
|
||||||
}
|
}
|
||||||
|
if (registryObject.get() == ModItems.CONTAINER.get()) {
|
||||||
|
output.accept(ContainerBlockItem.createMk42Instance());
|
||||||
|
}
|
||||||
}))
|
}))
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package com.atsuishio.superbwarfare.item;
|
package com.atsuishio.superbwarfare.item;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockItemRenderer;
|
import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockItemRenderer;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||||
|
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
||||||
import software.bernie.geckolib.animatable.GeoItem;
|
import software.bernie.geckolib.animatable.GeoItem;
|
||||||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
|
||||||
|
@ -50,4 +56,24 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack createInstance(Entity entity) {
|
||||||
|
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.put("Entity", entity.serializeNBT());
|
||||||
|
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createInstance(EntityType<?> entityType) {
|
||||||
|
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putString("EntityType", EntityType.getKey(entityType).toString());
|
||||||
|
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack createMk42Instance() {
|
||||||
|
return createInstance(ModEntities.MK_42.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue