Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Loadable #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
12 changes: 9 additions & 3 deletions block/src/main/java/nova/sample/block/BlockStateful.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import nova.core.component.Passthrough;
import nova.core.component.misc.Collider;
import nova.core.component.renderer.StaticRenderer;
import nova.core.component.transform.Orientation;
import nova.core.network.NetworkTarget;
import nova.core.network.Packet;
import nova.core.network.Syncable;
import nova.core.network.Sync;
import nova.core.network.Syncable;
import nova.core.render.model.MeshModel;
import nova.core.render.model.Model;
import nova.core.render.pipeline.OrientationRenderPipeline;
import nova.core.retention.Storable;
import nova.core.retention.Store;
import nova.core.util.math.RotationUtil;
Expand All @@ -31,9 +33,13 @@ public class BlockStateful extends Block implements Storable, Stateful, Syncable
@Sync
private double angle = 0;

@Store
@Sync
private Orientation orientation = new Orientation(this).hookBasedOnEntity();

public BlockStateful() {
components.add(new Collider(this).isOpaqueCube(false));
components.add(new StaticRenderer().onRender(model -> {
components.add(new StaticRenderer().onRender(new OrientationRenderPipeline(orientation).build().andThen(model -> {
Model grinderModel = NovaBlock.grinderModel.getModel();

grinderModel
Expand All @@ -44,7 +50,7 @@ public BlockStateful() {
((MeshModel)grinderModel).bindAll(NovaBlock.grinderTexture);

model.children.add(grinderModel);
}));
})));
components.add(new Category("buildingBlocks"));
//components.add(new TestComponent());

Expand Down
4 changes: 2 additions & 2 deletions block/src/main/java/nova/sample/block/BlockStateless.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public BlockStateless() {
}

public void onRightClick(RightClickEvent evt) {
System.out.println("Sending Packet: 1234");
NovaBlock.logger.info("Sending Packet: 1234");
NovaBlock.networkManager.sync(this);
}

@Override
public void read(Packet packet) {
System.out.println("Received packet: " + packet.readInt());
NovaBlock.logger.info("Received packet: " + packet.readInt());
}

@Override
Expand Down
55 changes: 32 additions & 23 deletions block/src/main/java/nova/sample/block/NovaBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

import nova.core.block.BlockFactory;
import nova.core.block.BlockManager;
import nova.core.event.bus.GlobalEvents;
import nova.core.item.ItemFactory;
import nova.core.item.ItemManager;
import nova.core.loader.Loadable;
import nova.core.loader.Mod;
import nova.core.network.NetworkManager;
import nova.core.recipes.RecipeManager;
import nova.core.recipes.crafting.ItemIngredient;
import nova.core.recipes.crafting.ShapedCraftingRecipe;
import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.render.RenderManager;
import nova.core.render.model.ModelProvider;
import nova.core.render.model.TechneModelProvider;
import nova.core.render.texture.BlockTexture;
import nova.core.render.texture.EntityTexture;
import org.slf4j.Logger;

/**
* A test Nova Mod
*
* @author Calclavia
*/
@Mod(id = NovaBlock.MOD_ID, name = "Nova Example Block", version = "0.0.1", novaVersion = "0.0.1")
public class NovaBlock implements Loadable {
public class NovaBlock {

public static final String MOD_ID = "novablock";

Expand All @@ -40,44 +41,52 @@ public class NovaBlock implements Loadable {
public static ModelProvider grinderModel;

public static NetworkManager networkManager;
public static Logger logger;

public final BlockManager blockManager;
public final ItemManager itemManager;
public final RenderManager renderManager;
public final RecipeManager recipeManager;

public NovaBlock(BlockManager blockManager,
ItemManager itemManager,
RenderManager renderManager,
NetworkManager networkManager,
RecipeManager recipeManager) {
this.blockManager = blockManager;
this.itemManager = itemManager;
this.renderManager = renderManager;
this.recipeManager = recipeManager;
public final GlobalEvents events;

public NovaBlock(Logger logger,
GlobalEvents events,
BlockManager blockManager,
ItemManager itemManager,
RenderManager renderManager,
NetworkManager networkManager,
RecipeManager recipeManager) {
this.events = events;

this.events.on(RenderManager.Init.class).bind(evt -> this.registerRenderer(evt.manager));
this.events.on(BlockManager.Init.class).bind(evt -> this.registerBlocks(evt.manager));
this.events.on(ItemManager.Init.class).bind(evt -> this.registerItems(evt.manager));
this.events.on(RecipeManager.Init.class).bind(evt -> this.registerRecipes(evt.manager));

NovaBlock.networkManager = networkManager;
NovaBlock.logger = logger;
}

@Override
public void preInit() {
private void registerRenderer(RenderManager renderManager) {
steelTexture = renderManager.registerTexture(new BlockTexture(MOD_ID, "block_steel"));
grinderTexture = renderManager.registerTexture(new BlockTexture(MOD_ID, "grinder"));

grinderEntityTexture = renderManager.registerTexture(new EntityTexture(MOD_ID, "grinder_entity"));
grinderModel = renderManager.registerModel(new TechneModelProvider(MOD_ID, "grinder"));
}

private void registerBlocks(BlockManager blockManager) {
blockStateful = blockManager.register(MOD_ID + ":stateful", BlockStateful::new);
blockStateless = blockManager.register(MOD_ID + ":simple", BlockStateless::new);
}

private void registerItems(ItemManager itemManager) {
itemBlockStateful = itemManager.getItemFromBlock(blockStateful);
itemBlockStateless = itemManager.getItemFromBlock(blockStateless);
}

grinderEntityTexture = renderManager.registerTexture(new EntityTexture(MOD_ID, "grinder_entity"));
grinderModel = renderManager.registerModel(new TechneModelProvider(MOD_ID, "grinder"));

private void registerRecipes(RecipeManager recipeManager) {
// try to add a recipe
//ItemIngredient stickIngredient = ItemIngredient.forItem("minecraft:stick"); //TODO: This should be obtained from some dictonary too
ItemIngredient stickIngredient = ItemIngredient.forDictionary("stickWood");
ItemIngredient ingotIngredient = ItemIngredient.forDictionary("ingotIron");

recipeManager.addRecipe(new ShapedCraftingRecipe(itemBlockStateless.build(), "AAA-ABA-AAA", ingotIngredient, stickIngredient));
recipeManager.addRecipe(new ShapedCraftingRecipe(itemBlockStateless, "AAA-ABA-AAA", ingotIngredient, stickIngredient));
}
}
6 changes: 6 additions & 0 deletions block/src/main/resources/assets/novablock/lang/en-US.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOVA Test Language File
# @author Calclavia

# Blocks
block.novablock.stateful.name=Stateful Block
block.novablock.simple.name=Stateless Block
6 changes: 0 additions & 6 deletions block/src/main/resources/assets/novablock/lang/en_US.lang

This file was deleted.

24 changes: 21 additions & 3 deletions entity/src/main/java/nova/sample/entity/NovaEntity.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
package nova.sample.entity;

import nova.core.entity.EntityManager;
import nova.core.loader.Loadable;
import nova.core.event.bus.GlobalEvents;
import nova.core.loader.Mod;
import nova.core.render.RenderManager;
import org.slf4j.Logger;

/**
* Used to test NOVA entities.
*
* @author ExE Boss
*/
@Mod(id = NovaEntity.MOD_ID, name = "Nova Example Entity", version = "0.0.1", novaVersion = "0.0.1")
public class NovaEntity implements Loadable {
public class NovaEntity {

public static final String MOD_ID = "novaentity";

public final Logger logger;
public final GlobalEvents events;
public final EntityManager entityManager;
public final RenderManager renderManager;

public NovaEntity(EntityManager entityManager,
public NovaEntity(Logger logger,
GlobalEvents events,
EntityManager entityManager,
RenderManager renderManager) {
this.logger = logger;
this.events = events;
this.entityManager = entityManager;
this.renderManager = renderManager;

events.on(RenderManager.Init.class).bind(evt -> this.registerRenderer(evt.manager));
events.on(EntityManager.Init.class).bind(evt -> this.registerEntities(evt.manager));
}

private void registerRenderer(RenderManager renderManager) {

}

private void registerEntities(EntityManager entityManager) {

}
}
39 changes: 27 additions & 12 deletions gui/src/main/java/nova/sample/gui/NovaGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import nova.core.block.BlockFactory;
import nova.core.block.BlockManager;
import nova.core.event.bus.GlobalEvents;
import nova.gui.Background;
import nova.gui.ComponentEvent.ActionEvent;
import nova.gui.Gui;
Expand All @@ -16,25 +17,25 @@
import nova.gui.layout.FlowLayout;
import nova.core.item.ItemFactory;
import nova.core.item.ItemManager;
import nova.core.loader.Loadable;
import nova.core.loader.Mod;
import nova.core.network.NetworkManager;
import nova.core.network.NetworkTarget.Side;
import nova.core.recipes.RecipeManager;
import nova.core.recipes.crafting.ItemIngredient;
import nova.core.recipes.crafting.ShapedCraftingRecipe;
import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.render.Color;
import nova.core.render.RenderManager;
import nova.core.render.texture.BlockTexture;
import nova.sample.gui.block.BlockSimpleTest;
import org.slf4j.Logger;

/**
* A test Nova Mod
*
* @author Calclavia
*/
@Mod(id = NovaGui.MOD_ID, name = "Nova GUI example", version = "0.0.1", novaVersion = "0.0.1")
public class NovaGui implements Loadable {
public class NovaGui {

public static final String MOD_ID = "novaexamplegui";

Expand All @@ -44,30 +45,41 @@ public class NovaGui implements Loadable {
public static BlockTexture steelTexture;
public static GuiManager guiFactory;
public static NetworkManager networkManager;
public static Logger logger;

public final GlobalEvents events;
public final BlockManager blockManager;
public final ItemManager itemManager;
public final RenderManager renderManager;
public final RecipeManager recipeManager;

public NovaGui(BlockManager blockManager,
public NovaGui(Logger logger,
GlobalEvents events,
BlockManager blockManager,
ItemManager itemManager,
RenderManager renderManager,
GuiManager guiFactory,
RecipeManager recipeManager,
NetworkManager networkManager) {
this.events = events;
this.blockManager = blockManager;
this.itemManager = itemManager;
this.renderManager = renderManager;
this.recipeManager = recipeManager;

NovaGui.networkManager = networkManager;
events.on(RenderManager.Init.class).bind(evt -> this.registerRenderer(evt.manager));
events.on(BlockManager.Init.class).bind(evt -> this.registerBlocks(evt.manager));
events.on(ItemManager.Init.class).bind(evt -> this.registerItems(evt.manager));
events.on(RecipeManager.Init.class).bind(evt -> this.registerRecipes(evt.manager));
events.on(GuiManager.Init.class).bind(evt -> this.registerGui(evt.manager));

NovaGui.logger = logger;
NovaGui.networkManager = networkManager;
NovaGui.guiFactory = guiFactory;
}

public static void initializeGUI() {
guiFactory.register("testgui", () -> new Gui("testgui")
private void registerGui(GuiManager guiManager) {
guiManager.register("testgui", () -> new Gui("testgui")
.add(new Button("testbutton2", "I'm EAST")
.setMaximumSize(Integer.MAX_VALUE, 120)

Expand Down Expand Up @@ -101,20 +113,23 @@ public static void initializeGUI() {
);
}

@Override
public void preInit() {
private void registerBlocks(BlockManager blockManager) {
blockTest = blockManager.register(MOD_ID + ":gui", BlockSimpleTest::new);
}

private void registerItems(ItemManager itemManager) {
itemBlockTest = itemManager.getItemFromBlock(blockTest);
}

private void registerRenderer(RenderManager renderManager) {
steelTexture = renderManager.registerTexture(new BlockTexture(MOD_ID, "block_steel"));
}

private void registerRecipes(RecipeManager recipeManager) {
// try to add a recipe
//ItemIngredient stickIngredient = ItemIngredient.forItem("minecraft:stick"); //TODO: This should be obtained from some dictonary too
ItemIngredient stickIngredient = ItemIngredient.forDictionary("stickWood");
ItemIngredient ingotIngredient = ItemIngredient.forDictionary("ingotIron");
recipeManager.addRecipe(new ShapedCraftingRecipe(itemBlockTest.build(), "AAA-ABA-AAA", ingotIngredient, stickIngredient));

initializeGUI();
recipeManager.addRecipe(new ShapedCraftingRecipe(itemBlockTest, "AAA-ABA-AAA", ingotIngredient, stickIngredient));
}
}
3 changes: 1 addition & 2 deletions gui/src/main/java/nova/sample/gui/block/BlockSimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public BlockSimpleTest() {
}

public void onRightClick(RightClickEvent evt) {
NovaGui.initializeGUI();
NovaGui.guiFactory.showGui("testgui", evt.entity, position());

System.out.println("Sending Packet: 1234");
Expand All @@ -38,7 +37,7 @@ public void onRightClick(RightClickEvent evt) {

@Override
public void read(Packet packet) {
System.out.println("Received packet: " + packet.readInt());
NovaGui.logger.info("Received packet: {}", packet.readInt());
}

@Override
Expand Down
1 change: 1 addition & 0 deletions item/src/main/java/nova/sample/item/ItemScrewdriver.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package nova.sample.item;

import nova.core.component.Category;
Expand Down
Loading