调整幸运集装箱的角标存储方式
This commit is contained in:
parent
63817a8aff
commit
4f3c41def4
5 changed files with 47 additions and 9 deletions
|
@ -1,4 +1,30 @@
|
|||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"bonus_rolls": 0.0,
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
],
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "superbwarfare:lucky_container"
|
||||
}
|
||||
],
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:copy_components",
|
||||
"include": [
|
||||
"minecraft:block_entity_data"
|
||||
],
|
||||
"source": "block_entity"
|
||||
}
|
||||
],
|
||||
"rolls": 1.0
|
||||
}
|
||||
],
|
||||
"random_sequence": "superbwarfare:blocks/lucky_container"
|
||||
}
|
|
@ -34,6 +34,8 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||
|
||||
@Nullable
|
||||
public ResourceLocation location;
|
||||
@Nullable
|
||||
public ResourceLocation icon;
|
||||
public int tick = 0;
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
@ -109,6 +111,9 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||
if (tag.contains("Location", 8)) {
|
||||
this.location = ResourceLocation.parse(tag.getString("Location"));
|
||||
}
|
||||
if (tag.contains("Icon", 8)) {
|
||||
this.icon = ResourceLocation.parse(tag.getString("Icon"));
|
||||
}
|
||||
this.tick = tag.getInt("Tick");
|
||||
}
|
||||
|
||||
|
@ -119,6 +124,9 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||
if (this.location != null) {
|
||||
tag.putString("Location", this.location.toString());
|
||||
}
|
||||
if (this.icon != null) {
|
||||
tag.putString("Icon", this.icon.toString());
|
||||
}
|
||||
tag.putInt("Tick", this.tick);
|
||||
}
|
||||
|
||||
|
@ -139,6 +147,9 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||
if (this.location != null) {
|
||||
tag.putString("Location", this.location.toString());
|
||||
}
|
||||
if (this.icon != null) {
|
||||
tag.putString("Icon", this.icon.toString());
|
||||
}
|
||||
BlockItem.setBlockEntityData(stack, this.getType(), tag);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.atsuishio.superbwarfare.client.decorator;
|
|||
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.item.common.container.LuckyContainerBlockItem;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
|
@ -20,7 +20,10 @@ public class LuckyContainerItemDecorator implements IItemDecorator {
|
|||
@ParametersAreNonnullByDefault
|
||||
public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int xOffset, int yOffset) {
|
||||
if (!(stack.getItem() instanceof LuckyContainerBlockItem)) return false;
|
||||
var tag = NBTTool.getTag(stack);
|
||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||
if (data == null) return false;
|
||||
|
||||
var tag = data.copyTag();
|
||||
if (!tag.contains("Icon")) return false;
|
||||
var iconTag = tag.getString("Icon");
|
||||
ResourceLocation icon = ResourceLocation.tryParse(iconTag);
|
||||
|
|
|
@ -73,8 +73,9 @@ public class ModBlockLootProvider extends BlockLootSubProvider {
|
|||
.include(DataComponents.CONTAINER_LOOT)
|
||||
)
|
||||
)));
|
||||
// TODO 改成正确的loot table
|
||||
this.add(ModBlocks.LUCKY_CONTAINER.get(), noDrop());
|
||||
this.add(ModBlocks.LUCKY_CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(ModBlocks.LUCKY_CONTAINER.get(),
|
||||
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.LUCKY_CONTAINER.get()))
|
||||
.apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY).include(DataComponents.BLOCK_ENTITY_DATA)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.client.renderer.item.LuckyContainerBlockItemR
|
|||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModBlocks;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -103,12 +102,10 @@ public class LuckyContainerBlockItem extends BlockItem implements GeoItem {
|
|||
CompoundTag tag = new CompoundTag();
|
||||
|
||||
tag.putString("Location", location.toString());
|
||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.LUCKY_CONTAINER.get(), tag);
|
||||
if (icon != null) {
|
||||
var iconTag = NBTTool.getTag(stack);
|
||||
iconTag.putString("Icon", icon.toString());
|
||||
NBTTool.saveTag(stack, iconTag);
|
||||
tag.putString("Icon", icon.toString());
|
||||
}
|
||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.LUCKY_CONTAINER.get(), tag);
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue