Skip to content

Commit

Permalink
push some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed May 10, 2024
1 parent 7b592c0 commit 18f8927
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "Create the Main Class"
layout: doc
---

Create a new class in your mod package that implements `MModdingModInitializer`:

`MModdingExempleMod.java`
```java
public class MModdingExempleMod implements MModdingModInitializer {

public static MModdingModContainer mod;

@Override
public List<ElementsInitializer> getElementsInitializers() {
List<ElementsInitializer> elementsInitializers = new ArrayList<>();
// Check the "Use ElementsInitializer" page
return elementsInitializers;
}

@Override
public void onInitialize(ModContainer mod) {
MModdingModInitializer.super.onInitialize();
MModdingExempleMod.mod = MModdingModContainer.from(mod);

// Your amazing code here
}
}
```

<div class="notification is-warning">Warning: You must replace <code>MModdingExempleMod</code> by your mod's name!</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
layout: doc
title: "Use Custom BlockEntity Types"
---

With the `CustomBlockEntityType` class provided by the MModding Library, registering a new BlockEntityType is more simple.

## **Create your BlockEntity class**

`MModdingBlockEntity.java`
```java
public class MModdingBlockEntity extends BlockEntity {

public MModdingBlockEntity(BlockPos pos, BlockState state) {
super(NOTHING, pos, state);
}
}
```

<div class="notification is-warning">Warning: "NOTHING" is not permanent, we will replace it later.</div>

## **Create and register your BlockEntityType**

In your BlockEntityTypes class:

`BlockEntityTypes.class`
```java
public class BlockEntityTypes {
public static final CustomBlockEntityType<TestBlockEntity> TEST = new CustomBlockEntityType<>(MModdingBlockEntity::new, BLOCK)
.createAndRegister(new Identifier("mmodding_exemple_mod", "testBlockEntityType"));
}
```

<div class="notification is-success">Tip: Replace "BLOCK" by the instance of the block that uses the BlockEntity.</div>

**Update your BlockEntity class**

Replace "NOTHING" by your BlockEntityType:

`MModdingBlockEntity.java`
```java
public class MModdingBlockEntity extends BlockEntity {

public MModdingBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.TEST.getBlockEntityTypeIfCreated(), pos, state);
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
layout: doc
title: "Use Element Initializers"
---

## **Create an Element Initializer**

`MModdingModBlocks.java`
```java
public class MModdingModBlocks implements ElementsInitializer {

// Init a block
public static final CustomBlock MMODDING_BLOCK = new CustomBlock(
QuiltBlockSettings.of(Material.METAL)
)

@Override
public void register() {
// And register it
MMODDING_BLOCK.register(
new Identifier("mmodding_exemple_mod", "mmodding_block")
);
}
}
```

<div class="notification is-success">Tip: For more information about the <code>CustomBlock</code>, go to the <code>CustomBlock</code> Page</div>

# **Register an Elements Initializer**

`MModdingExampleMod.java`
```java
public class MModdingExempleMod implements MModdingModInitializer {

// ...

@Override
public List<ElementsInitializer> getElementsInitializers() {
List<ElementsInitializer> elementsInitializers = new ArrayList<>();
// Add the Element Initializer in the List
elementsInitializers.add(new MModdingModBlocks());
return elementsInitializers;
}

// ...
}
```

By doing this, you won't need to call `MModdingExempleMod#register`.

0 comments on commit 18f8927

Please sign in to comment.