This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96f87ee
commit c678655
Showing
9 changed files
with
210 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
src/main/java/net/dumbcode/projectnublar/core/blocks/elements/TestBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
package net.dumbcode.projectnublar.core.blocks.elements; | ||
|
||
import net.dumbcode.projectnublar.core.blocks.DumbBlock; | ||
import net.dumbcode.projectnublar.core.blocks.entity.DumbBlockEntities; | ||
import net.dumbcode.projectnublar.core.blocks.entity.DumbEntityBlock; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import software.bernie.geckolib.renderer.GeoBlockRenderer; | ||
|
||
public class TestBlock extends DumbBlock { | ||
public class TestBlock extends DumbEntityBlock { | ||
|
||
public TestBlock() { | ||
super(Properties.ofFullCopy(Blocks.AMETHYST_BLOCK)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) { | ||
return null; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/net/dumbcode/projectnublar/core/blocks/entity/DumbBlockEntities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.dumbcode.projectnublar.core.blocks.entity; | ||
|
||
import net.dumbcode.projectnublar.core.blocks.entity.elements.TestBlockEntity; | ||
import net.dumbcode.projectnublar.core.registry.Registrar; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraftforge.registries.RegistryObject; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import software.bernie.geckolib.model.DefaultedBlockGeoModel; | ||
import software.bernie.geckolib.renderer.GeoBlockRenderer; | ||
|
||
import java.util.function.Function; | ||
|
||
import static net.dumbcode.projectnublar.ProjectNublar.MOD_ID; | ||
|
||
public class DumbBlockEntities { | ||
public enum Entities { | ||
TEST_BLOCK( | ||
TestBlockEntity::new, | ||
TestBlockEntity.Renderer::new | ||
); | ||
|
||
private final BlockEntityType.BlockEntitySupplier<DumbBlockEntity> blockEntityConstructor; | ||
private final BlockEntityRendererProvider<DumbBlockEntity> renderer; | ||
private final Registry registry = Registry.of( | ||
RegistryObject.create(new ResourceLocation(MOD_ID, getRegisterName()), Registrar.BLOCK_ENTITY_TYPES.getRegistryKey(), MOD_ID) | ||
); | ||
private final DefaultedBlockGeoModel<DumbBlockEntity> model = new DefaultedBlockGeoModel<>(new ResourceLocation(MOD_ID, getRegisterName())); | ||
|
||
Entities(BlockEntityType.BlockEntitySupplier<DumbBlockEntity> blockEntityConstructor, BlockEntityRendererProvider<DumbBlockEntity> renderer) { | ||
this.blockEntityConstructor = blockEntityConstructor; | ||
this.renderer = renderer; | ||
} | ||
|
||
public Registry getRegistry() { | ||
return this.registry; | ||
} | ||
|
||
public DefaultedBlockGeoModel<DumbBlockEntity> getModel() { | ||
return this.model; | ||
} | ||
|
||
public BlockEntityRendererProvider<DumbBlockEntity> getRenderer() { | ||
return this.renderer; | ||
} | ||
|
||
public BlockEntityType.BlockEntitySupplier<DumbBlockEntity> getBlockEntityConstructor() { | ||
return this.blockEntityConstructor; | ||
} | ||
|
||
public @NotNull String getRegisterName() { | ||
return this.name().toLowerCase(); | ||
} | ||
} | ||
|
||
public record Registry(RegistryObject<BlockEntityType<DumbBlockEntity>> blockEntityType) { | ||
@Contract("_ -> new") | ||
public static @NotNull Registry of(RegistryObject<BlockEntityType<DumbBlockEntity>> blockEntityType) { | ||
return new Registry(blockEntityType); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/dumbcode/projectnublar/core/blocks/entity/DumbBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.dumbcode.projectnublar.core.blocks.entity; | ||
|
||
import com.google.common.base.Function; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import software.bernie.geckolib.animatable.GeoBlockEntity; | ||
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; | ||
import software.bernie.geckolib.renderer.GeoBlockRenderer; | ||
import software.bernie.geckolib.util.GeckoLibUtil; | ||
|
||
public abstract class DumbBlockEntity extends BlockEntity implements GeoBlockEntity { | ||
|
||
private final DumbBlockEntities.Entities entity; | ||
protected final AnimatableInstanceCache instanceCache = GeckoLibUtil.createInstanceCache(this); | ||
|
||
protected DumbBlockEntity(DumbBlockEntities.Entities entity, BlockPos pPos, BlockState pBlockState) { | ||
super(entity.getRegistry().blockEntityType().get(), pPos, pBlockState); | ||
this.entity = entity; | ||
} | ||
|
||
public Function<EntityRendererProvider.Context, ? extends GeoBlockRenderer<DumbBlockEntity>> getRenderer() { | ||
return Renderer::new; | ||
} | ||
|
||
@Override | ||
public AnimatableInstanceCache getAnimatableInstanceCache() { | ||
return instanceCache; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/net/dumbcode/projectnublar/core/blocks/entity/DumbEntityBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.dumbcode.projectnublar.core.blocks.entity; | ||
|
||
import net.dumbcode.projectnublar.core.blocks.DumbBlock; | ||
import net.minecraft.world.level.block.EntityBlock; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class DumbEntityBlock extends DumbBlock implements EntityBlock { | ||
protected DumbEntityBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public @NotNull RenderShape getRenderShape(@NotNull BlockState pState) { | ||
return RenderShape.ENTITYBLOCK_ANIMATED; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/net/dumbcode/projectnublar/core/blocks/entity/elements/TestBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.dumbcode.projectnublar.core.blocks.entity.elements; | ||
|
||
import net.dumbcode.projectnublar.core.blocks.entity.DumbBlockEntities; | ||
import net.dumbcode.projectnublar.core.blocks.entity.DumbBlockEntity; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import software.bernie.geckolib.core.animation.AnimatableManager; | ||
import software.bernie.geckolib.renderer.GeoBlockRenderer; | ||
|
||
public class TestBlockEntity extends DumbBlockEntity { | ||
private static final DumbBlockEntities.Entities ENTITY = DumbBlockEntities.Entities.TEST_BLOCK; | ||
|
||
public static class Renderer extends GeoBlockRenderer<DumbBlockEntity> { | ||
public Renderer(BlockEntityRendererProvider.Context context) { | ||
super(ENTITY.getModel()); | ||
} | ||
} | ||
|
||
public TestBlockEntity(BlockPos pPos, BlockState pBlockState) { | ||
super(ENTITY, pPos, pBlockState); | ||
} | ||
|
||
@Override | ||
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
import net.dumbcode.projectnublar.ProjectNublar; | ||
import net.dumbcode.projectnublar.core.blocks.IDumbBlock; | ||
import net.dumbcode.projectnublar.core.blocks.DumbBlocks; | ||
import net.dumbcode.projectnublar.core.blocks.entity.DumbBlockEntities; | ||
import net.dumbcode.projectnublar.core.blocks.entity.DumbBlockEntity; | ||
import net.dumbcode.projectnublar.core.creativetab.DumbCreativeTab; | ||
import net.dumbcode.projectnublar.core.creativetab.DumbCreativeTabs; | ||
import net.dumbcode.projectnublar.core.entities.DumbEntities; | ||
import net.dumbcode.projectnublar.core.mobs.DumbMobs; | ||
import net.dumbcode.projectnublar.core.exceptions.UtilityClassException; | ||
import net.dumbcode.projectnublar.core.items.DumbItem; | ||
import net.dumbcode.projectnublar.core.items.DumbItems; | ||
|
@@ -15,7 +17,9 @@ | |
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraftforge.client.event.EntityRenderersEvent; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fluids.FluidType; | ||
|
@@ -25,7 +29,8 @@ | |
import net.minecraftforge.registries.RegisterEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import static net.dumbcode.projectnublar.ProjectNublar.MOD_ID; | ||
|
@@ -43,13 +48,15 @@ public class Registrar { | |
// viscosity, can fluid drown, can it be passed on a boat, extinguish fire etc. | ||
public static final DeferredRegister<FluidType> FLUID_TYPES = DeferredRegister.create(ForgeRegistries.FLUID_TYPES, MOD_ID); | ||
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MOD_ID); | ||
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, MOD_ID); | ||
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MOD_ID); | ||
|
||
public static void register(@NotNull IEventBus bus) { | ||
BLOCKS.register(bus); | ||
ITEMS.register(bus); | ||
CREATIVE_MODE_TABS.register(bus); | ||
ENTITY_TYPES.register(bus); | ||
BLOCK_ENTITY_TYPES.register(bus); | ||
FLUID_TYPES.register(bus); | ||
FLUIDS.register(bus); | ||
} | ||
|
@@ -77,12 +84,24 @@ public static void register(@NotNull RegisterEvent event) { | |
} | ||
}); | ||
event.register(Registrar.ENTITY_TYPES.getRegistryKey(), helper -> { | ||
for(DumbEntities.Entities entity : DumbEntities.Entities.values()) { | ||
for(DumbMobs.Mobs entity : DumbMobs.Mobs.values()) { | ||
helper.register(ProjectNublar.resourceLocation(entity.name().toLowerCase()), entity.getNativeType()); | ||
} | ||
}); | ||
event.register( | ||
Registrar.CREATIVE_MODE_TABS.getRegistryKey(), helper -> { | ||
event.register(Registrar.BLOCK_ENTITY_TYPES.getRegistryKey(), helper -> { | ||
for (DumbBlockEntities.Entities entity : DumbBlockEntities.Entities.values()) { | ||
List<Block> validBlocks = new ArrayList<>(); | ||
for (DumbBlocks.Blocks block : DumbBlocks.Blocks.values()) { | ||
DumbBlockEntities.Entities associatedEntity = block.getMetadata().associatedEntity(); | ||
if (associatedEntity == null) continue; | ||
if (!associatedEntity.equals(entity)) continue; | ||
validBlocks.add(block.getRegistry().block().get()); | ||
} | ||
BlockEntityType.Builder<DumbBlockEntity> builder = BlockEntityType.Builder.of(entity.getBlockEntityConstructor(), validBlocks.toArray(new Block[0])); | ||
helper.register(ProjectNublar.resourceLocation(entity.getRegisterName()), builder.build(null)); | ||
Check warning on line 101 in src/main/java/net/dumbcode/projectnublar/core/registry/Registrar.java
|
||
} | ||
}); | ||
event.register(Registrar.CREATIVE_MODE_TABS.getRegistryKey(), helper -> { | ||
for (DumbCreativeTabs.CreativeTabs creativeTab : DumbCreativeTabs.CreativeTabs.values()) { | ||
Supplier<DumbCreativeTab> creativeTabConstructor = creativeTab.getCreativeTabConstructor(); | ||
DumbCreativeTab instance = creativeTabConstructor.get(); | ||
|
@@ -92,6 +111,13 @@ public static void register(@NotNull RegisterEvent event) { | |
}); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) { | ||
for (DumbBlockEntities.Entities blockEntity : DumbBlockEntities.Entities.values()) { | ||
event.registerBlockEntityRenderer(blockEntity.getRegistry().blockEntityType().get(), blockEntity.getRenderer()); | ||
} | ||
} | ||
|
||
private Registrar() { | ||
throw new UtilityClassException(); | ||
} | ||
|