移植小补给箱
This commit is contained in:
parent
ab392f1648
commit
327ac99017
5 changed files with 37 additions and 32 deletions
|
@ -40,7 +40,6 @@ import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class SmallContainerBlock extends BaseEntityBlock {
|
public class SmallContainerBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||||
|
@ -148,6 +147,5 @@ public class SmallContainerBlock extends BaseEntityBlock {
|
||||||
level.getBlockEntity(pos, ModBlockEntities.SMALL_CONTAINER.get()).ifPresent((blockEntity) -> blockEntity.saveToItem(stack, level.registryAccess()));
|
level.getBlockEntity(pos, ModBlockEntities.SMALL_CONTAINER.get()).ifPresent((blockEntity) -> blockEntity.saveToItem(stack, level.registryAccess()));
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,14 @@ package com.atsuishio.superbwarfare.block.entity;
|
||||||
import com.atsuishio.superbwarfare.block.SmallContainerBlock;
|
import com.atsuishio.superbwarfare.block.SmallContainerBlock;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||||
|
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.particles.ParticleTypes;
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
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.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
@ -22,6 +25,8 @@ import net.minecraft.world.level.block.Blocks;
|
||||||
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 net.minecraft.world.level.storage.loot.LootParams;
|
import net.minecraft.world.level.storage.loot.LootParams;
|
||||||
|
import net.minecraft.world.level.storage.loot.LootTable;
|
||||||
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -38,7 +43,7 @@ import java.util.List;
|
||||||
public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
|
public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ResourceLocation lootTable;
|
public ResourceKey<LootTable> lootTable;
|
||||||
public long lootTableSeed;
|
public long lootTableSeed;
|
||||||
public int tick = 0;
|
public int tick = 0;
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -99,7 +104,7 @@ public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
||||||
super.loadAdditional(tag, registries);
|
super.loadAdditional(tag, registries);
|
||||||
|
|
||||||
if (tag.contains("LootTable", 8)) {
|
if (tag.contains("LootTable", 8)) {
|
||||||
this.lootTable = ResourceLocation.bySeparator(tag.getString("LootTable"), ':');
|
this.lootTable = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(tag.getString("LootTable")));
|
||||||
this.lootTableSeed = tag.getLong("LootTableSeed");
|
this.lootTableSeed = tag.getLong("LootTableSeed");
|
||||||
}
|
}
|
||||||
this.tick = tag.getInt("Tick");
|
this.tick = tag.getInt("Tick");
|
||||||
|
@ -111,7 +116,7 @@ public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
||||||
super.saveAdditional(tag, registries);
|
super.saveAdditional(tag, registries);
|
||||||
|
|
||||||
if (this.lootTable != null) {
|
if (this.lootTable != null) {
|
||||||
tag.putString("LootTable", this.lootTable.toString());
|
tag.putString("LootTable", this.lootTable.location().toString());
|
||||||
if (this.lootTableSeed != 0L) {
|
if (this.lootTableSeed != 0L) {
|
||||||
tag.putLong("LootTableSeed", this.lootTableSeed);
|
tag.putLong("LootTableSeed", this.lootTableSeed);
|
||||||
}
|
}
|
||||||
|
@ -142,18 +147,16 @@ public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
||||||
BlockItem.setBlockEntityData(stack, this.getType(), tag);
|
BlockItem.setBlockEntityData(stack, this.getType(), tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLootTable(ResourceLocation pLootTable, long pLootTableSeed) {
|
public void setLootTable(ResourceKey<LootTable> pLootTable, long pLootTableSeed) {
|
||||||
this.lootTable = pLootTable;
|
this.lootTable = pLootTable;
|
||||||
this.lootTableSeed = pLootTableSeed;
|
this.lootTableSeed = pLootTableSeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ItemStack> unpackLootTable(@Nullable Player pPlayer) {
|
public List<ItemStack> unpackLootTable(@Nullable Player pPlayer) {
|
||||||
if (this.lootTable != null && this.level != null && this.level.getServer() != null) {
|
if (this.lootTable != null && this.level != null && this.level.getServer() != null) {
|
||||||
|
LootTable loottable = this.level.getServer().reloadableRegistries().getLootTable(this.lootTable);
|
||||||
// TODO loot table resource key?
|
|
||||||
// LootTable loottable = this.level.getServer().reloadableRegistries().getLootTable(this.lootTable);
|
|
||||||
if (pPlayer instanceof ServerPlayer) {
|
if (pPlayer instanceof ServerPlayer) {
|
||||||
// CriteriaTriggers.GENERATE_LOOT.trigger((ServerPlayer) pPlayer, this.lootTable);
|
CriteriaTriggers.GENERATE_LOOT.trigger((ServerPlayer) pPlayer, this.lootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lootTable = null;
|
this.lootTable = null;
|
||||||
|
@ -163,7 +166,7 @@ public class SmallContainerBlockEntity extends BlockEntity implements GeoBlockEn
|
||||||
builder.withLuck(pPlayer.getLuck()).withParameter(LootContextParams.THIS_ENTITY, pPlayer);
|
builder.withLuck(pPlayer.getLuck()).withParameter(LootContextParams.THIS_ENTITY, pPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return loottable.getRandomItems(builder.create(LootContextParamSets.CHEST), this.lootTableSeed).stream().toList();
|
return loottable.getRandomItems(builder.create(LootContextParamSets.CHEST), this.lootTableSeed).stream().toList();
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,8 +125,6 @@ public class ModItems {
|
||||||
*/
|
*/
|
||||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(Registries.ITEM, Mod.MODID);
|
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(Registries.ITEM, Mod.MODID);
|
||||||
|
|
||||||
public static final DeferredHolder<Item, ContainerBlockItem> CONTAINER = ITEMS.register("container", ContainerBlockItem::new);
|
|
||||||
public static final DeferredHolder<Item, SmallContainerBlockItem> SMALL_CONTAINER = ITEMS.register("small_container", SmallContainerBlockItem::new);
|
|
||||||
public static final DeferredHolder<Item, DeferredSpawnEggItem> SENPAI_SPAWN_EGG = ITEMS.register("senpai_spawn_egg", () -> new DeferredSpawnEggItem(ModEntities.SENPAI::value, -11584987, -14014413, new Item.Properties()));
|
public static final DeferredHolder<Item, DeferredSpawnEggItem> SENPAI_SPAWN_EGG = ITEMS.register("senpai_spawn_egg", () -> new DeferredSpawnEggItem(ModEntities.SENPAI::value, -11584987, -14014413, new Item.Properties()));
|
||||||
public static final DeferredHolder<Item, Item> ANCIENT_CPU = ITEMS.register("ancient_cpu", () -> new Item(new Item.Properties().rarity(Rarity.RARE)));
|
public static final DeferredHolder<Item, Item> ANCIENT_CPU = ITEMS.register("ancient_cpu", () -> new Item(new Item.Properties().rarity(Rarity.RARE)));
|
||||||
public static final DeferredHolder<Item, Item> PROPELLER = ITEMS.register("propeller", () -> new Item(new Item.Properties()));
|
public static final DeferredHolder<Item, Item> PROPELLER = ITEMS.register("propeller", () -> new Item(new Item.Properties()));
|
||||||
|
@ -278,6 +276,8 @@ public class ModItems {
|
||||||
public static final DeferredHolder<Item, BlockItem> SILVER_BLOCK = block(ModBlocks.SILVER_BLOCK);
|
public static final DeferredHolder<Item, BlockItem> SILVER_BLOCK = block(ModBlocks.SILVER_BLOCK);
|
||||||
public static final DeferredHolder<Item, BlockItem> CEMENTED_CARBIDE_BLOCK = block(ModBlocks.CEMENTED_CARBIDE_BLOCK);
|
public static final DeferredHolder<Item, BlockItem> CEMENTED_CARBIDE_BLOCK = block(ModBlocks.CEMENTED_CARBIDE_BLOCK);
|
||||||
public static final DeferredHolder<Item, BlockItem> FUMO_25 = block(ModBlocks.FUMO_25);
|
public static final DeferredHolder<Item, BlockItem> FUMO_25 = block(ModBlocks.FUMO_25);
|
||||||
|
public static final DeferredHolder<Item, ContainerBlockItem> CONTAINER = BLOCKS.register("container", ContainerBlockItem::new);
|
||||||
|
public static final DeferredHolder<Item, SmallContainerBlockItem> SMALL_CONTAINER = BLOCKS.register("small_container", SmallContainerBlockItem::new);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perk Items
|
* Perk Items
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.init;
|
package com.atsuishio.superbwarfare.init;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.item.ArmorPlate;
|
import com.atsuishio.superbwarfare.item.*;
|
||||||
import com.atsuishio.superbwarfare.item.BatteryItem;
|
|
||||||
import com.atsuishio.superbwarfare.item.C4Bomb;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
|
@ -17,8 +15,6 @@ import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static com.atsuishio.superbwarfare.item.ContainerBlockItem.CONTAINER_ENTITIES;
|
|
||||||
|
|
||||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ModTabs {
|
public class ModTabs {
|
||||||
|
@ -67,16 +63,12 @@ public class ModTabs {
|
||||||
.title(Component.translatable("item_group.superbwarfare.item"))
|
.title(Component.translatable("item_group.superbwarfare.item"))
|
||||||
.icon(() -> new ItemStack(ModItems.TARGET_DEPLOYER.get()))
|
.icon(() -> new ItemStack(ModItems.TARGET_DEPLOYER.get()))
|
||||||
.displayItems((param, output) -> ModItems.ITEMS.getEntries().forEach(registryObject -> {
|
.displayItems((param, output) -> ModItems.ITEMS.getEntries().forEach(registryObject -> {
|
||||||
if (registryObject.get() == ModItems.CONTAINER.get()) {
|
output.accept(registryObject.get());
|
||||||
CONTAINER_ENTITIES.stream().map(Supplier::get).forEach(output::accept);
|
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
|
||||||
} else {
|
output.accept(ArmorPlate.getInfiniteInstance());
|
||||||
output.accept(registryObject.get());
|
}
|
||||||
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
|
if (registryObject.get() instanceof BatteryItem batteryItem) {
|
||||||
output.accept(ArmorPlate.getInfiniteInstance());
|
output.accept(batteryItem.makeFullEnergyStack());
|
||||||
}
|
|
||||||
if (registryObject.get() instanceof BatteryItem batteryItem) {
|
|
||||||
output.accept(batteryItem.makeFullEnergyStack());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.build());
|
.build());
|
||||||
|
@ -86,7 +78,16 @@ public class ModTabs {
|
||||||
.title(Component.translatable("item_group.superbwarfare.block"))
|
.title(Component.translatable("item_group.superbwarfare.block"))
|
||||||
.icon(() -> new ItemStack(ModItems.SANDBAG.get()))
|
.icon(() -> new ItemStack(ModItems.SANDBAG.get()))
|
||||||
.withTabsBefore(ITEM_TAB.getKey())
|
.withTabsBefore(ITEM_TAB.getKey())
|
||||||
.displayItems((param, output) -> ModItems.BLOCKS.getEntries().forEach(registryObject -> output.accept(registryObject.get())))
|
.displayItems((param, output) -> ModItems.BLOCKS.getEntries().forEach(registryObject -> {
|
||||||
|
if (registryObject.get() == ModItems.CONTAINER.get()) {
|
||||||
|
ContainerBlockItem.CONTAINER_ENTITIES.stream().map(Supplier::get).forEach(output::accept);
|
||||||
|
} else if (registryObject.get() == ModItems.SMALL_CONTAINER.get()) {
|
||||||
|
output.accept(registryObject.get());
|
||||||
|
SmallContainerBlockItem.SMALL_CONTAINER_LOOT_TABLES.stream().map(Supplier::get).forEach(output::accept);
|
||||||
|
} else {
|
||||||
|
output.accept(registryObject.get());
|
||||||
|
}
|
||||||
|
}))
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|
|
@ -6,10 +6,13 @@ import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
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 net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
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.level.storage.loot.LootTable;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
|
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
|
||||||
|
@ -68,13 +71,13 @@ public class SmallContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createInstance(ResourceLocation lootTable) {
|
public static ItemStack createInstance(ResourceLocation lootTable) {
|
||||||
return createInstance(lootTable, 0L);
|
return createInstance(ResourceKey.create(Registries.LOOT_TABLE, lootTable), 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createInstance(ResourceLocation lootTable, long lootTableSeed) {
|
public static ItemStack createInstance(ResourceKey<LootTable> lootTable, long lootTableSeed) {
|
||||||
ItemStack stack = new ItemStack(ModBlocks.SMALL_CONTAINER.get());
|
ItemStack stack = new ItemStack(ModBlocks.SMALL_CONTAINER.get());
|
||||||
CompoundTag tag = new CompoundTag();
|
CompoundTag tag = new CompoundTag();
|
||||||
tag.putString("LootTable", lootTable.toString());
|
tag.putString("LootTable", lootTable.location().toString());
|
||||||
if (lootTableSeed != 0L) {
|
if (lootTableSeed != 0L) {
|
||||||
tag.putLong("LootTableSeed", lootTableSeed);
|
tag.putLong("LootTableSeed", lootTableSeed);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue