添加幸运集装箱的角标
This commit is contained in:
parent
4cc1131e52
commit
63817a8aff
4 changed files with 57 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.decorator.ContainerItemDecorator;
|
||||
import com.atsuishio.superbwarfare.client.decorator.LuckyContainerItemDecorator;
|
||||
import com.atsuishio.superbwarfare.client.overlay.*;
|
||||
import com.atsuishio.superbwarfare.client.renderer.block.*;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.*;
|
||||
|
@ -68,5 +70,6 @@ public class ClientRenderHandler {
|
|||
@SubscribeEvent
|
||||
public static void registerItemDecorations(RegisterItemDecorationsEvent event) {
|
||||
event.register(ModItems.CONTAINER.get(), new ContainerItemDecorator());
|
||||
event.register(ModItems.LUCKY_CONTAINER.get(), new LuckyContainerItemDecorator());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atsuishio.superbwarfare.client;
|
||||
package com.atsuishio.superbwarfare.client.decorator;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.RenderHelper;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||
import com.atsuishio.superbwarfare.item.common.container.ContainerBlockItem;
|
||||
import net.minecraft.client.Minecraft;
|
|
@ -0,0 +1,36 @@
|
|||
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.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.client.IItemDecorator;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class LuckyContainerItemDecorator implements IItemDecorator {
|
||||
|
||||
@Override
|
||||
@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);
|
||||
if (!tag.contains("Icon")) return false;
|
||||
var iconTag = tag.getString("Icon");
|
||||
ResourceLocation icon = ResourceLocation.tryParse(iconTag);
|
||||
if (icon == null) return false;
|
||||
|
||||
var pose = guiGraphics.pose();
|
||||
pose.pushPose();
|
||||
RenderHelper.preciseBlit(guiGraphics, icon, xOffset, yOffset, 200, 0, 0, 8, 8, 8, 8);
|
||||
pose.popPose();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ 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;
|
||||
|
@ -25,6 +26,7 @@ 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 org.jetbrains.annotations.Nullable;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||
import software.bernie.geckolib.animation.AnimatableManager;
|
||||
|
@ -41,10 +43,10 @@ import java.util.function.Supplier;
|
|||
public class LuckyContainerBlockItem extends BlockItem implements GeoItem {
|
||||
|
||||
public static final List<Supplier<ItemStack>> LUCKY_CONTAINERS = List.of(
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("mobile_vehicles")),
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("land_vehicles")),
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("aircraft")),
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("controllable_turrets"))
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("mobile_vehicles"), Mod.loc("textures/gui/vehicle/type/civilian.png")),
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("land_vehicles"), Mod.loc("textures/gui/vehicle/type/land.png")),
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("aircraft"), Mod.loc("textures/gui/vehicle/type/aircraft.png")),
|
||||
() -> LuckyContainerBlockItem.createInstance(Mod.loc("controllable_turrets"), Mod.loc("textures/gui/vehicle/type/defense.png"))
|
||||
);
|
||||
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
@ -96,12 +98,21 @@ public class LuckyContainerBlockItem extends BlockItem implements GeoItem {
|
|||
return this.cache;
|
||||
}
|
||||
|
||||
public static ItemStack createInstance(ResourceLocation location) {
|
||||
public static ItemStack createInstance(ResourceLocation location, @Nullable ResourceLocation icon) {
|
||||
ItemStack stack = new ItemStack(ModBlocks.LUCKY_CONTAINER.get());
|
||||
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);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack createInstance(ResourceLocation location) {
|
||||
return createInstance(location, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue