Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ idea {

jar {
//classifier 'slim'
setDuplicatesStrategy(DuplicatesStrategy.WARN)
afterEvaluate {
configurations.shade.each { dep ->
from(project.zipTree(dep)) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/github/alexthe666/citadel/Citadel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.alexthe666.citadel.item.ItemCitadelBook;
import com.github.alexthe666.citadel.item.ItemCitadelDebug;
import com.github.alexthe666.citadel.item.ItemCustomRender;
import com.github.alexthe666.citadel.item.component.CustomRenderDisplay;
import com.github.alexthe666.citadel.server.CitadelEvents;
import com.github.alexthe666.citadel.server.block.CitadelLecternBlock;
import com.github.alexthe666.citadel.server.block.CitadelLecternBlockEntity;
Expand All @@ -15,7 +16,13 @@
import com.github.alexthe666.citadel.web.WebHelper;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -60,13 +67,18 @@ public class Citadel {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(BuiltInRegistries.ITEM, "citadel");
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(BuiltInRegistries.BLOCK, "citadel");
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, "citadel");
public static final DeferredRegister.DataComponents DATA_COMPONENTS = DeferredRegister.createDataComponents(Registries.DATA_COMPONENT_TYPE, "citadel");

public static final DeferredHolder<Item, ItemCitadelDebug> DEBUG_ITEM = ITEMS.register("debug", () -> new ItemCitadelDebug(new Item.Properties()));
public static final DeferredHolder<Item, ItemCitadelBook> CITADEL_BOOK = ITEMS.register("citadel_book", () -> new ItemCitadelBook(new Item.Properties().stacksTo(1)));
public static final DeferredHolder<Item, ItemCustomRender> EFFECT_ITEM = ITEMS.register("effect_item", () -> new ItemCustomRender(new Item.Properties().stacksTo(1)));
public static final DeferredHolder<Item, ItemCustomRender> FANCY_ITEM = ITEMS.register("fancy_item", () -> new ItemCustomRender(new Item.Properties().stacksTo(1)));
public static final DeferredHolder<Item, ItemCustomRender> ICON_ITEM = ITEMS.register("icon_item", () -> new ItemCustomRender(new Item.Properties().stacksTo(1)));

public static final DeferredHolder<DataComponentType<?>, DataComponentType<CustomRenderDisplay>> CUSTOM_RENDER_DISPLAY = DATA_COMPONENTS.registerComponentType("custom_render_display", builder -> builder.persistent(CustomRenderDisplay.CODEC));
public static final DeferredHolder<DataComponentType<?>, DataComponentType<ResourceLocation>> ICON_LOCATION = DATA_COMPONENTS.registerComponentType("icon_location", builder -> builder.persistent(ResourceLocation.CODEC).networkSynchronized(ResourceLocation.STREAM_CODEC));
public static final DeferredHolder<DataComponentType<?>, DataComponentType<ResourceKey<MobEffect>>> DISPLAY_EFFECT = DATA_COMPONENTS.registerComponentType("display_effect", builder -> builder.persistent(ResourceKey.codec(Registries.MOB_EFFECT)).networkSynchronized(ResourceKey.streamCodec(Registries.MOB_EFFECT)));

public static final Supplier<Block> LECTERN = BLOCKS.register("lectern", () -> new CitadelLecternBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.LECTERN)));

public static final Supplier<BlockEntityType<CitadelLecternBlockEntity>> LECTERN_BE = BLOCK_ENTITIES.register("lectern", () -> BlockEntityType.Builder.of(CitadelLecternBlockEntity::new, LECTERN.get()).build(null));
Expand All @@ -75,6 +87,7 @@ public Citadel(ModContainer modContainer, IEventBus bus) {
ITEMS.register(bus);
BLOCKS.register(bus);
BLOCK_ENTITIES.register(bus);
DATA_COMPONENTS.register(bus);
final DeferredRegister<MapCodec<? extends BiomeModifier>> serializers = DeferredRegister.create(NeoForgeRegistries.BIOME_MODIFIER_SERIALIZERS, "citadel");
serializers.register(bus);
serializers.register("mob_spawn_probability", SpawnProbabilityModifier::makeCodec);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.alexthe666.citadel.client;

import com.github.alexthe666.citadel.Citadel;
import com.github.alexthe666.citadel.item.component.CustomRenderDisplay;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Axis;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
Expand All @@ -13,6 +15,7 @@
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.item.ItemDisplayContext;
Expand All @@ -27,7 +30,6 @@
public class CitadelItemstackRenderer extends BlockEntityWithoutLevelRenderer {

private static final ResourceLocation DEFAULT_ICON_TEXTURE = ResourceLocation.parse("citadel:textures/gui/book/icon_default.png");
private static final Map<String, ResourceLocation> LOADED_ICONS = new HashMap<>();

private static List<Holder.Reference<MobEffect>> mobEffectList = null;

Expand All @@ -43,44 +45,33 @@ public void renderByItem(ItemStack stack, ItemDisplayContext displayContext, Pos
if (stack.getItem() == Citadel.FANCY_ITEM.get()) {
Random random = new Random();
boolean animateAnyways = false;
ItemStack toRender = null;
//TODO: convert to component system
/*
if (stack.getTag() != null && stack.getTag().contains("DisplayItem")) {
String displayID = stack.getTag().getString("DisplayItem");
toRender = new ItemStack(ForgeRegistries.ITEMS.getValue(ResourceLocation.parse(displayID)));
if (stack.getTag().contains("DisplayItemNBT")) {
try {
toRender.setTag(stack.getTag().getCompound("DisplayItemNBT"));
} catch (Exception e) {
toRender = new ItemStack(Items.BARRIER);
}
}
}
if (toRender == null) {

CustomRenderDisplay display = stack.getOrDefault(Citadel.CUSTOM_RENDER_DISPLAY, CustomRenderDisplay.DEFAULT);

if (!stack.has(Citadel.CUSTOM_RENDER_DISPLAY)) {
animateAnyways = true;
toRender = new ItemStack(Items.BARRIER);
}

poseStack.pushPose();
poseStack.translate(0.5F, 0.5f, 0.5f);
if(stack.getTag() != null && stack.getTag().contains("DisplayShake") && stack.getTag().getBoolean("DisplayShake")) {
if(display.shake()) {
poseStack.translate((random.nextFloat() - 0.5F) * 0.1F, (random.nextFloat() - 0.5F) * 0.1F, (random.nextFloat() - 0.5F) * 0.1F);
}
if(animateAnyways || stack.getTag() != null && stack.getTag().contains("DisplayBob") && stack.getTag().getBoolean("DisplayBob")){
if(animateAnyways || display.bob()){
poseStack.translate(0, 0.05F + 0.1F * Mth.sin(0.3F * ticksExisted), 0);
}
if(stack.getTag() != null && stack.getTag().contains("DisplaySpin") && stack.getTag().getBoolean("DisplaySpin")){
if(display.spin()){
poseStack.mulPose(Axis.YP.rotationDegrees(6 * ticksExisted));
}
if(animateAnyways || stack.getTag() != null && stack.getTag().contains("DisplayZoom") && stack.getTag().getBoolean("DisplayZoom")) {
if(animateAnyways || display.zoom()) {
float scale = (float) (1F + 0.15F * (Math.sin(ticksExisted * 0.3F) + 1F));
poseStack.scale(scale, scale, scale);
}
if(stack.getTag() != null && stack.getTag().contains("DisplayScale") && stack.getTag().getFloat("DisplayScale") != 1.0F){
float scale = stack.getTag().getFloat("DisplayScale");
if(display.scale() != 1.0F){
float scale = display.scale();
poseStack.scale(scale, scale, scale);
}*/
Minecraft.getInstance().getItemRenderer().renderStatic(toRender, displayContext, packedLight, packedOverlay, poseStack, buffer, null, id);
}
Minecraft.getInstance().getItemRenderer().renderStatic(display.item(), displayContext, packedLight, packedOverlay, poseStack, buffer, null, id);
poseStack.popPose();
}
if (stack.getItem() == Citadel.EFFECT_ITEM.get()) {
Expand All @@ -90,16 +81,21 @@ public void renderByItem(ItemStack stack, ItemDisplayContext displayContext, Pos
// RenderSystem.enableAlphaTest();
RenderSystem.enableDepthTest();
Holder<MobEffect> effect;
//TODO: convert to component system
if (mobEffectList == null) {
mobEffectList = BuiltInRegistries.MOB_EFFECT.holders().toList();
}
int size = mobEffectList.size();
int time = (int) (Util.getMillis() / 500);
effect = mobEffectList.get(time % size);
if (effect == null) {
effect = MobEffects.MOVEMENT_SPEED.getDelegate();

if (stack.has(Citadel.DISPLAY_EFFECT)) {
effect = BuiltInRegistries.MOB_EFFECT.getHolderOrThrow(stack.get(Citadel.DISPLAY_EFFECT));
} else {
if (mobEffectList == null) {
mobEffectList = BuiltInRegistries.MOB_EFFECT.holders().toList();
}
int size = mobEffectList.size();
int time = (int) (Util.getMillis() / 500);
effect = mobEffectList.get(time % size);
if (effect == null) {
effect = MobEffects.MOVEMENT_SPEED.getDelegate();
}
}

MobEffectTextureManager potionspriteuploader = Minecraft.getInstance().getMobEffectTextures();
poseStack.pushPose();
poseStack.translate(0, 0, 0.5F);
Expand All @@ -114,32 +110,24 @@ public void renderByItem(ItemStack stack, ItemDisplayContext displayContext, Pos
bufferbuilder.addVertex(mx, (float) 0, (float) 1, (float) 0).setUv(sprite.getU0(), sprite.getV0()).setColor(br, br, br, 255).setLight(packedLight);
bufferbuilder.addVertex(mx, (float) 0, (float) 0, (float) 0).setUv(sprite.getU0(), sprite.getV1()).setColor(br, br, br, 255).setLight(packedLight);
bufferbuilder.addVertex(mx, (float) 1, (float) 0, (float) 0).setUv(sprite.getU1(), sprite.getV1()).setColor(br, br, br, 255).setLight(packedLight);
BufferUploader.drawWithShader(bufferbuilder.buildOrThrow());
poseStack.popPose();
}
if (stack.getItem() == Citadel.ICON_ITEM.get()) {
//TODO: convert to component system
/*if (stack.getTag() != null && stack.getTag().contains("IconLocation")) {
String iconLocationStr = stack.getTag().getString("IconLocation");
if(LOADED_ICONS.containsKey(iconLocationStr)){
texture = LOADED_ICONS.get(iconLocationStr);
}else{
texture = ResourceLocation.parse(iconLocationStr);
LOADED_ICONS.put(iconLocationStr, texture);
}
}*/
ResourceLocation texture = stack.getOrDefault(Citadel.ICON_LOCATION, DEFAULT_ICON_TEXTURE);
poseStack.pushPose();
poseStack.translate(0, 0, 0.5F);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, DEFAULT_ICON_TEXTURE);
Tesselator tessellator = Tesselator.getInstance();
RenderSystem.setShaderTexture(0, texture);
BufferBuilder bufferbuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
Matrix4f mx = poseStack.last().pose();
int br = 255;
bufferbuilder.addVertex(mx, (float) 1, (float) 1, (float) 0).setUv(1, 0).setColor(br, br, br, 255).setLight(packedLight);
bufferbuilder.addVertex(mx, (float) 0, (float) 1, (float) 0).setUv(0, 0).setColor(br, br, br, 255).setLight(packedLight);
bufferbuilder.addVertex(mx, (float) 0, (float) 0, (float) 0).setUv(0, 1).setColor(br, br, br, 255).setLight(packedLight);
bufferbuilder.addVertex(mx, (float) 1, (float) 0, (float) 0).setUv(1, 1).setColor(br, br, br, 255).setLight(packedLight);
BufferUploader.drawWithShader(bufferbuilder.buildOrThrow());
poseStack.popPose();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.alexthe666.citadel.item.component;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

public record CustomRenderDisplay(
ItemStack item,
boolean shake,
boolean bob,
boolean spin,
boolean zoom,
float scale
) {
public static final CustomRenderDisplay DEFAULT = new CustomRenderDisplay(new ItemStack(Items.BARRIER), false, false, false, false, 1f);

public static final Codec<CustomRenderDisplay> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Codec.withAlternative(ItemStack.CODEC, Codec.unit(new ItemStack(Items.BARRIER)))
.fieldOf("item")
.forGetter(CustomRenderDisplay::item),
Codec.BOOL
.optionalFieldOf("shake", false)
.forGetter(CustomRenderDisplay::shake),
Codec.BOOL
.optionalFieldOf("bob", false)
.forGetter(CustomRenderDisplay::bob),
Codec.BOOL
.optionalFieldOf("spin", false)
.forGetter(CustomRenderDisplay::spin),
Codec.BOOL
.optionalFieldOf("zoom", false)
.forGetter(CustomRenderDisplay::zoom),
Codec.FLOAT
.optionalFieldOf("scale", 1f)
.forGetter(CustomRenderDisplay::scale)
)
.apply(instance, CustomRenderDisplay::new)
);
}