注册幸运集装箱

This commit is contained in:
17146 2025-07-13 21:04:34 +08:00 committed by Light_Quanta
parent bb59072a6a
commit b12b263361
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
27 changed files with 551 additions and 21 deletions

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.api.event;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;

View file

@ -0,0 +1,114 @@
package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.block.entity.LuckyContainerBlockEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModTags;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
@SuppressWarnings("deprecation")
public class LuckyContainerBlock extends BaseEntityBlock {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty OPENED = BooleanProperty.create("opened");
public LuckyContainerBlock() {
this(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(3.0f).noOcclusion().requiresCorrectToolForDrops());
}
public LuckyContainerBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPENED, false));
}
@Override
@ParametersAreNonnullByDefault
protected @NotNull ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (level.isClientSide
|| state.getValue(OPENED)
|| !(level.getBlockEntity(pos) instanceof LuckyContainerBlockEntity)
) return ItemInteractionResult.FAIL;
if (!stack.is(ModTags.Items.CROWBAR)) {
player.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.crowbar"), true);
return ItemInteractionResult.FAIL;
}
return ItemInteractionResult.FAIL;
}
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, @NotNull BlockState pState, @NotNull BlockEntityType<T> pBlockEntityType) {
if (!pLevel.isClientSide) {
return createTickerHelper(pBlockEntityType, ModBlockEntities.LUCKY_CONTAINER.get(), LuckyContainerBlockEntity::serverTick);
}
return null;
}
@Override
@ParametersAreNonnullByDefault
public @NotNull VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return state.getValue(OPENED) ? box(1, 0, 1, 15, 14, 15) : box(0, 0, 0, 16, 15, 16);
}
@Override
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
return simpleCodec(LuckyContainerBlock::new);
}
@Override
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos blockPos, @NotNull BlockState blockState) {
return new LuckyContainerBlockEntity(blockPos, blockState);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING).add(OPENED);
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(OPENED, false);
}
@Override
@ParametersAreNonnullByDefault
public @NotNull ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state) {
ItemStack itemstack = super.getCloneItemStack(level, pos, state);
level.getBlockEntity(pos, ModBlockEntities.LUCKY_CONTAINER.get()).ifPresent((blockEntity) -> blockEntity.saveToItem(itemstack, level.registryAccess()));
return itemstack;
}
}

View file

@ -0,0 +1,105 @@
package com.atsuishio.superbwarfare.block.entity;
import com.atsuishio.superbwarfare.block.ContainerBlock;
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.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.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoBlockEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.*;
import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.ParametersAreNonnullByDefault;
public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEntity {
public int tick = 0;
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public LuckyContainerBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.CONTAINER.get(), pos, state);
}
public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, LuckyContainerBlockEntity blockEntity) {
if (!pState.getValue(ContainerBlock.OPENED)) {
return;
}
if (blockEntity.tick < 20) {
blockEntity.tick++;
blockEntity.setChanged();
if (blockEntity.tick == 18) {
ParticleTool.sendParticle((ServerLevel) pLevel, ParticleTypes.EXPLOSION, pPos.getX(), pPos.getY() + 1, pPos.getZ(), 40, 1.5, 1.5, 1.5, 1, false);
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 {
var direction = pState.getValue(ContainerBlock.FACING);
pLevel.setBlockAndUpdate(pPos, Blocks.AIR.defaultBlockState());
}
}
private PlayState predicate(AnimationState<LuckyContainerBlockEntity> event) {
if (this.getBlockState().getValue(ContainerBlock.OPENED)) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.container.open"));
}
return PlayState.STOP;
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "controller", 0, this::predicate));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache;
}
@Override
@ParametersAreNonnullByDefault
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
this.tick = tag.getInt("Tick");
}
@Override
@ParametersAreNonnullByDefault
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries);
tag.putInt("Tick", this.tick);
}
@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}
@Override
public @NotNull CompoundTag getUpdateTag(HolderLookup.@NotNull Provider registries) {
return this.saveWithFullMetadata(registries);
}
@Override
@ParametersAreNonnullByDefault
public void saveToItem(ItemStack stack, HolderLookup.Provider registries) {
CompoundTag tag = new CompoundTag();
BlockItem.setBlockEntityData(stack, this.getType(), tag);
}
}

View file

@ -1,10 +1,7 @@
package com.atsuishio.superbwarfare.client;
import com.atsuishio.superbwarfare.client.overlay.*;
import com.atsuishio.superbwarfare.client.renderer.block.ChargingStationBlockEntityRenderer;
import com.atsuishio.superbwarfare.client.renderer.block.ContainerBlockEntityRenderer;
import com.atsuishio.superbwarfare.client.renderer.block.FuMO25BlockEntityRenderer;
import com.atsuishio.superbwarfare.client.renderer.block.SmallContainerBlockEntityRenderer;
import com.atsuishio.superbwarfare.client.renderer.block.*;
import com.atsuishio.superbwarfare.client.tooltip.*;
import com.atsuishio.superbwarfare.client.tooltip.component.*;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
@ -39,6 +36,7 @@ public class ClientRenderHandler {
event.registerBlockEntityRenderer(ModBlockEntities.FUMO_25.get(), context -> new FuMO25BlockEntityRenderer());
event.registerBlockEntityRenderer(ModBlockEntities.CHARGING_STATION.get(), context -> new ChargingStationBlockEntityRenderer());
event.registerBlockEntityRenderer(ModBlockEntities.SMALL_CONTAINER.get(), context -> new SmallContainerBlockEntityRenderer());
event.registerBlockEntityRenderer(ModBlockEntities.LUCKY_CONTAINER.get(), context -> new LuckyContainerBlockEntityRenderer());
}
@SubscribeEvent

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.client;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;

View file

@ -0,0 +1,24 @@
package com.atsuishio.superbwarfare.client.model.block;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.block.entity.LuckyContainerBlockEntity;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.GeoModel;
public class LuckyContainerBlockModel extends GeoModel<LuckyContainerBlockEntity> {
@Override
public ResourceLocation getAnimationResource(LuckyContainerBlockEntity animatable) {
return Mod.loc("animations/container.animation.json");
}
@Override
public ResourceLocation getModelResource(LuckyContainerBlockEntity animatable) {
return Mod.loc("geo/container.geo.json");
}
@Override
public ResourceLocation getTextureResource(LuckyContainerBlockEntity animatable) {
return Mod.loc("textures/block/lucky_container.png");
}
}

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.client.model.item;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.GeoModel;

View file

@ -0,0 +1,24 @@
package com.atsuishio.superbwarfare.client.model.item;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.common.container.LuckyContainerBlockItem;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.GeoModel;
public class LuckyContainerItemModel extends GeoModel<LuckyContainerBlockItem> {
@Override
public ResourceLocation getAnimationResource(LuckyContainerBlockItem animatable) {
return Mod.loc("animations/container.animation.json");
}
@Override
public ResourceLocation getModelResource(LuckyContainerBlockItem animatable) {
return Mod.loc("geo/container.geo.json");
}
@Override
public ResourceLocation getTextureResource(LuckyContainerBlockItem animatable) {
return Mod.loc("textures/block/lucky_container.png");
}
}

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.client.model.item;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.SmallContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.SmallContainerBlockItem;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.GeoModel;

View file

@ -0,0 +1,20 @@
package com.atsuishio.superbwarfare.client.renderer.block;
import com.atsuishio.superbwarfare.block.entity.LuckyContainerBlockEntity;
import com.atsuishio.superbwarfare.client.model.block.LuckyContainerBlockModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.renderer.GeoBlockRenderer;
public class LuckyContainerBlockEntityRenderer extends GeoBlockRenderer<LuckyContainerBlockEntity> {
public LuckyContainerBlockEntityRenderer() {
super(new LuckyContainerBlockModel());
}
@Override
public RenderType getRenderType(LuckyContainerBlockEntity animatable, ResourceLocation texture, MultiBufferSource bufferSource, float partialTick) {
return RenderType.entityTranslucent(getTextureLocation(animatable));
}
}

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.client.renderer.item;
import com.atsuishio.superbwarfare.client.model.item.ContainerItemModel;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;

View file

@ -0,0 +1,20 @@
package com.atsuishio.superbwarfare.client.renderer.item;
import com.atsuishio.superbwarfare.client.model.item.LuckyContainerItemModel;
import com.atsuishio.superbwarfare.item.common.container.LuckyContainerBlockItem;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.renderer.GeoItemRenderer;
public class LuckyContainerBlockItemRenderer extends GeoItemRenderer<LuckyContainerBlockItem> {
public LuckyContainerBlockItemRenderer() {
super(new LuckyContainerItemModel());
}
@Override
public RenderType getRenderType(LuckyContainerBlockItem animatable, ResourceLocation texture, MultiBufferSource bufferSource, float partialTick) {
return RenderType.entityTranslucent(getTextureLocation(animatable));
}
}

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.client.renderer.item;
import com.atsuishio.superbwarfare.client.model.item.SmallContainerItemModel;
import com.atsuishio.superbwarfare.item.SmallContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.SmallContainerBlockItem;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;

View file

@ -12,7 +12,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.*;
import com.mojang.math.Axis;
import net.minecraft.nbt.CompoundTag;

View file

@ -9,7 +9,7 @@ import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool;

View file

@ -8,7 +8,7 @@ import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModSerializers;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.OBB;
import com.atsuishio.superbwarfare.tools.ParticleTool;

View file

@ -9,7 +9,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.InventoryTool;

View file

@ -30,4 +30,6 @@ public class ModBlockEntities {
() -> BlockEntityType.Builder.of(VehicleDeployerBlockEntity::new, ModBlocks.VEHICLE_DEPLOYER.get()).build(null));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<SuperbItemInterfaceBlockEntity>> SUPERB_ITEM_INTERFACE = REGISTRY.register("superb_item_interface",
() -> BlockEntityType.Builder.of(SuperbItemInterfaceBlockEntity::new, ModBlocks.SUPERB_ITEM_INTERFACE.get()).build(null));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<LuckyContainerBlockEntity>> LUCKY_CONTAINER = REGISTRY.register("lucky_container",
() -> BlockEntityType.Builder.of(LuckyContainerBlockEntity::new, ModBlocks.LUCKY_CONTAINER.get()).build(null));
}

View file

@ -50,5 +50,6 @@ public class ModBlocks {
public static final DeferredHolder<Block, SmallContainerBlock> SMALL_CONTAINER = REGISTRY.register("small_container", () -> new SmallContainerBlock());
public static final DeferredHolder<Block, VehicleDeployerBlock> VEHICLE_DEPLOYER = REGISTRY.register("vehicle_deployer", VehicleDeployerBlock::new);
public static final DeferredHolder<Block, AircraftCatapultBlock> AIRCRAFT_CATAPULT = REGISTRY.register("aircraft_catapult", AircraftCatapultBlock::new);
public static final DeferredHolder<Block, SuperbItemInterfaceBlock> SUPERB_ITEM_INTERFACE = REGISTRY.register("superb_item_interface", () -> new SuperbItemInterfaceBlock());
public static final DeferredHolder<Block, SuperbItemInterfaceBlock> SUPERB_ITEM_INTERFACE = REGISTRY.register("superb_item_interface", SuperbItemInterfaceBlock::new);
public static final DeferredHolder<Block, LuckyContainerBlock> LUCKY_CONTAINER = REGISTRY.register("lucky_container", () -> new LuckyContainerBlock());
}

View file

@ -8,6 +8,9 @@ import com.atsuishio.superbwarfare.item.common.BlueprintItem;
import com.atsuishio.superbwarfare.item.common.MaterialPack;
import com.atsuishio.superbwarfare.item.common.ammo.*;
import com.atsuishio.superbwarfare.item.common.ammo.box.AmmoBox;
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.LuckyContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.SmallContainerBlockItem;
import com.atsuishio.superbwarfare.item.gun.handgun.*;
import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item;
import com.atsuishio.superbwarfare.item.gun.launcher.JavelinItem;
@ -288,12 +291,15 @@ public class ModItems {
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> 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);
public static final DeferredHolder<Item, VehicleDeployerBlockItem> VEHICLE_DEPLOYER = BLOCKS.register("vehicle_deployer", VehicleDeployerBlockItem::new);
public static final DeferredHolder<Item, BlockItem> AIRCRAFT_CATAPULT = block(ModBlocks.AIRCRAFT_CATAPULT);
public static final DeferredHolder<Item, BlockItem> SUPERB_ITEM_INTERFACE = block(ModBlocks.SUPERB_ITEM_INTERFACE);
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);
public static final DeferredHolder<Item, LuckyContainerBlockItem> LUCKY_CONTAINER = BLOCKS.register("lucky_container", LuckyContainerBlockItem::new);
public record Materials(
String name,
DeferredHolder<Item, Item> barrel,

View file

@ -2,7 +2,11 @@ package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.api.event.RegisterContainersEvent;
import com.atsuishio.superbwarfare.item.*;
import com.atsuishio.superbwarfare.item.ArmorPlate;
import com.atsuishio.superbwarfare.item.BatteryItem;
import com.atsuishio.superbwarfare.item.C4BombItem;
import com.atsuishio.superbwarfare.item.ElectricBaton;
import com.atsuishio.superbwarfare.item.common.container.SmallContainerBlockItem;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
@ -105,6 +109,8 @@ public class ModTabs {
.displayItems((param, output) -> ModItems.BLOCKS.getEntries().forEach(registryObject -> {
if (registryObject.get() == ModItems.CONTAINER.get()) {
RegisterContainersEvent.containers.forEach(output::accept);
} else if (registryObject.get() == ModItems.LUCKY_CONTAINER.get()) {
output.accept(registryObject.get());
} else if (registryObject.get() == ModItems.SMALL_CONTAINER.get()) {
output.accept(registryObject.get());
SmallContainerBlockItem.SMALL_CONTAINER_LOOT_TABLES.stream().map(Supplier::get).forEach(output::accept);

View file

@ -1,7 +1,7 @@
package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.SmallContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.container.SmallContainerBlockItem;
import com.google.common.collect.ImmutableSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.core.Holder;

View file

@ -1,4 +1,4 @@
package com.atsuishio.superbwarfare.item;
package com.atsuishio.superbwarfare.item.common.container;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.api.event.RegisterContainersEvent;

View file

@ -0,0 +1,86 @@
package com.atsuishio.superbwarfare.item.common.container;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.LuckyContainerBlockItemRenderer;
import com.atsuishio.superbwarfare.init.ModBlocks;
import com.atsuishio.superbwarfare.init.ModItems;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.animation.AnimationController;
import software.bernie.geckolib.animation.AnimationState;
import software.bernie.geckolib.animation.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.ParametersAreNonnullByDefault;
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
public class LuckyContainerBlockItem extends BlockItem implements GeoItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public LuckyContainerBlockItem() {
super(ModBlocks.LUCKY_CONTAINER.get(), new Properties().stacksTo(1).rarity(Rarity.EPIC));
}
@Override
public @NotNull InteractionResult useOn(@NotNull UseOnContext context) {
return InteractionResult.PASS;
}
@Override
@ParametersAreNonnullByDefault
public @NotNull InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
BlockHitResult playerPOVHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.WATER);
if (playerPOVHitResult.getType() == HitResult.Type.MISS) {
return super.use(level, player, hand);
}
BlockHitResult blockHitResult = playerPOVHitResult.withPosition(playerPOVHitResult.getBlockPos().above());
InteractionResult interactionresult = super.useOn(new UseOnContext(player, hand, blockHitResult));
return new InteractionResultHolder<>(interactionresult, player.getItemInHand(hand));
}
private PlayState predicate(AnimationState<LuckyContainerBlockItem> event) {
return PlayState.CONTINUE;
}
@SubscribeEvent
private static void registerItemExtensions(RegisterClientExtensionsEvent event) {
event.registerItem(new IClientItemExtensions() {
private final BlockEntityWithoutLevelRenderer renderer = new LuckyContainerBlockItemRenderer();
@Override
public @NotNull BlockEntityWithoutLevelRenderer getCustomRenderer() {
return renderer;
}
}, ModItems.LUCKY_CONTAINER);
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "controller", 0, this::predicate));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache;
}
}

View file

@ -1,4 +1,4 @@
package com.atsuishio.superbwarfare.item;
package com.atsuishio.superbwarfare.item.common.container;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.SmallContainerBlockItemRenderer;

View file

@ -0,0 +1,124 @@
{
"credit": "Made with Blockbench",
"parent": "builtin/entity",
"texture_size": [
128,
128
],
"display": {
"thirdperson_righthand": {
"rotation": [
90,
0,
0
],
"translation": [
0,
-2,
-6
],
"scale": [
0.4,
0.4,
0.4
]
},
"thirdperson_lefthand": {
"rotation": [
90,
0,
0
],
"translation": [
0,
-2,
-6
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_righthand": {
"rotation": [
-176.35,
27.92,
-176.98
],
"translation": [
-2,
0,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_lefthand": {
"rotation": [
-176.35,
27.92,
-176.98
],
"translation": [
-2,
0,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"ground": {
"translation": [
0,
-1.75,
0
],
"scale": [
0.5,
0.5,
0.5
]
},
"gui": {
"rotation": [
-155,
-45,
180
],
"translation": [
0,
-4.5,
0
],
"scale": [
0.65,
0.65,
0.65
]
},
"head": {
"translation": [
0,
-7,
0
]
},
"fixed": {
"translation": [
0,
-7.75,
1
]
}
},
"textures": {
"particle": "superbwarfare:block/container"
}
}