Skip to content

Commit

Permalink
Fixed few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Aug 3, 2024
1 parent 8fc8e7b commit 4151979
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package dev.latvian.mods.literalskyblock;

import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.Arrays;
import java.util.function.Supplier;

public interface LSBBlockEntities {
DeferredRegister<BlockEntityType<?>> REGISTER = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, LiteralSkyBlock.MOD_ID);

Supplier<BlockEntityType<SkyBlockEntity>> SKY_BLOCK = REGISTER.register("sky_block", () -> BlockEntityType.Builder.of(SkyBlockEntity::new, LSBBlocks.SKY_BLOCK.get()).build(null));
Supplier<BlockEntityType<VoidBlockEntity>> VOID_BLOCK = REGISTER.register("void_block", () -> BlockEntityType.Builder.of(VoidBlockEntity::new, LSBBlocks.VOID_BLOCK.get()).build(null));
Supplier<BlockEntityType<SkyBlockEntity>> SKY_BLOCK = REGISTER.register("sky_block", () -> BlockEntityType.Builder.of(SkyBlockEntity::new, Arrays.stream(ProjectionType.VALUES).map(p -> p.skyBlock).map(DeferredHolder::get).toArray(Block[]::new)).build(null));
}
5 changes: 0 additions & 5 deletions src/main/java/dev/latvian/mods/literalskyblock/LSBBlocks.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package dev.latvian.mods.literalskyblock;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredRegister;

public interface LSBBlocks {
DeferredRegister.Blocks REGISTER = DeferredRegister.createBlocks(LiteralSkyBlock.MOD_ID);

DeferredBlock<Block> SKY_BLOCK = REGISTER.registerBlock("sky_block", SkyBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.STONE));
DeferredBlock<Block> VOID_BLOCK = REGISTER.registerBlock("void_block", VoidBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.STONE));
}
5 changes: 0 additions & 5 deletions src/main/java/dev/latvian/mods/literalskyblock/LSBItems.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package dev.latvian.mods.literalskyblock;

import net.minecraft.world.item.BlockItem;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;

public interface LSBItems {
DeferredRegister.Items REGISTER = DeferredRegister.createItems(LiteralSkyBlock.MOD_ID);

DeferredItem<BlockItem> SKY_BLOCK = REGISTER.registerSimpleBlockItem("sky_block", LSBBlocks.SKY_BLOCK);
DeferredItem<BlockItem> VOID_BLOCK = REGISTER.registerSimpleBlockItem("void_block", LSBBlocks.VOID_BLOCK);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public class LSBModEventHandler {
@SubscribeEvent
public static void buildCreativeModeTabContents(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) {
event.accept(LSBItems.SKY_BLOCK, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
event.accept(LSBItems.VOID_BLOCK, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
for (var p : ProjectionType.VALUES) {
event.accept(p.skyBlockItem, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.latvian.mods.literalskyblock;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;

Expand All @@ -14,5 +16,10 @@ public LiteralSkyBlock(IEventBus bus) {
LSBBlocks.REGISTER.register(bus);
LSBItems.REGISTER.register(bus);
LSBBlockEntities.REGISTER.register(bus);

for (var p : ProjectionType.VALUES) {
p.skyBlock = LSBBlocks.REGISTER.registerBlock(p.getSerializedName() + "_block", b -> new SkyBlock(p, b), BlockBehaviour.Properties.ofFullCopy(Blocks.STONE));
p.skyBlockItem = LSBItems.REGISTER.registerSimpleBlockItem(p.skyBlock);
}
}
}
33 changes: 33 additions & 0 deletions src/main/java/dev/latvian/mods/literalskyblock/ProjectionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.latvian.mods.literalskyblock;

import com.mojang.serialization.Codec;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredItem;

public enum ProjectionType implements StringRepresentable {
SKY("sky", false),
VOID("void", false);

public static final ProjectionType[] VALUES = values();
public static final Codec<ProjectionType> CODEC = StringRepresentable.fromEnum(() -> VALUES);

private final String name;
public final boolean uvs;

public Object renderType;
public DeferredBlock<Block> skyBlock;
public DeferredItem<BlockItem> skyBlockItem;

ProjectionType(String name, boolean uvs) {
this.name = name;
this.uvs = uvs;
}

@Override
public String getSerializedName() {
return name;
}
}
31 changes: 18 additions & 13 deletions src/main/java/dev/latvian/mods/literalskyblock/SkyBlock.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.latvian.mods.literalskyblock;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
Expand All @@ -13,18 +14,26 @@
import org.jetbrains.annotations.Nullable;

public class SkyBlock extends BaseEntityBlock {
public SkyBlock(Properties properties) {
public static final MapCodec<SkyBlock> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
ProjectionType.CODEC.fieldOf("projection").forGetter(block -> block.projection),
Block.propertiesCodec()
).apply(instance, SkyBlock::new));

public final ProjectionType projection;

public SkyBlock(ProjectionType projection, Properties properties) {
super(properties);
this.projection = projection;
}

@Override
protected RenderShape getRenderShape(BlockState state) {
return RenderShape.INVISIBLE;
protected MapCodec<? extends BaseEntityBlock> codec() {
return CODEC;
}

@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return Block.simpleCodec(SkyBlock::new);
protected RenderShape getRenderShape(BlockState state) {
return RenderShape.INVISIBLE;
}

@Nullable
Expand All @@ -35,10 +44,8 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState state1, LevelAccessor level, BlockPos pos, BlockPos pos1) {
BlockEntity blockEntity = level.getBlockEntity(pos);

if (blockEntity instanceof SkyBlockEntity) {
((SkyBlockEntity) blockEntity).neighborChanged();
if (level.getBlockEntity(pos) instanceof SkyBlockEntity entity) {
entity.neighborChanged();
}

return super.updateShape(state, direction, state1, level, pos, pos1);
Expand All @@ -49,10 +56,8 @@ public BlockState updateShape(BlockState state, Direction direction, BlockState
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos pos1, boolean b) {
super.neighborChanged(state, level, pos, block, pos1, b);

BlockEntity blockEntity = level.getBlockEntity(pos);

if (blockEntity instanceof SkyBlockEntity) {
((SkyBlockEntity) blockEntity).neighborChanged();
if (level.getBlockEntity(pos) instanceof SkyBlockEntity entity) {
entity.neighborChanged();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

public class SkyBlockEntity extends BlockEntity {
private final Boolean[] shouldRender = new Boolean[6];
public final ProjectionType projection;

public SkyBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
this.projection = ((SkyBlock) state.getBlock()).projection;
}

public SkyBlockEntity(BlockPos pos, BlockState state) {
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/dev/latvian/mods/literalskyblock/VoidBlock.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RenderGuiEvent;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;

@EventBusSubscriber(modid = LiteralSkyBlock.MOD_ID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
Expand All @@ -14,8 +13,10 @@ public static void renderLast(RenderLevelStageEvent event) {
LSBClient.renderSky(event);
}

/*
@SubscribeEvent
public static void drawUI(RenderGuiEvent.Post event) {
LSBClient.drawUI(event.getGuiGraphics());
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import dev.latvian.mods.literalskyblock.LSBBlockEntities;
import dev.latvian.mods.literalskyblock.LiteralSkyBlock;
import dev.latvian.mods.literalskyblock.ProjectionType;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.neoforged.api.distmarker.Dist;
Expand All @@ -18,7 +20,9 @@ public class LSBClientModEventHandler {
@SubscribeEvent
public static void setup(FMLClientSetupEvent event) {
BlockEntityRenderers.register(LSBBlockEntities.SKY_BLOCK.get(), SkyBlockEntityRenderer::new);
BlockEntityRenderers.register(LSBBlockEntities.VOID_BLOCK.get(), SkyBlockEntityRenderer::new);

ProjectionType.SKY.renderType = LSBClient.SKY_RENDER_TYPE;
ProjectionType.VOID.renderType = RenderType.endGateway();
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.latvian.mods.literalskyblock.SkyBlockEntity;
import dev.latvian.mods.literalskyblock.VoidBlockEntity;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
Expand All @@ -17,7 +16,7 @@ public SkyBlockEntityRenderer(BlockEntityRendererProvider.Context context) {

@Override
public void render(SkyBlockEntity entity, float delta, PoseStack poseStack, MultiBufferSource source, int light1, int light2) {
renderCube(entity, poseStack.last().pose(), source.getBuffer(entity instanceof VoidBlockEntity ? RenderType.endGateway() : LSBClient.SKY_RENDER_TYPE));
renderCube(entity, poseStack.last().pose(), source.getBuffer(entity instanceof SkyBlockEntity e ? (RenderType) e.projection.renderType : RenderType.endGateway()));
}

private void renderCube(SkyBlockEntity entity, Matrix4f matrix, VertexConsumer buffer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
],
"key": {
"S": {
"tag": "forge:stone"
"tag": "c:stones"
},
"G": {
"item": "minecraft:amethyst_shard"
"tag": "c:gems/amethyst"
}
},
"result": {
"item": "literalskyblock:sky_block",
"id": "literalskyblock:sky_block",
"count": 8
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"result": {
"item": "literalskyblock:void_block",
"id": "literalskyblock:void_block",
"count": 8
}
}

0 comments on commit 4151979

Please sign in to comment.