-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added partial BlockEntity and custom screen support
- Loading branch information
1 parent
69f9889
commit a161188
Showing
30 changed files
with
1,042 additions
and
3 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
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
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
22 changes: 22 additions & 0 deletions
22
common/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachment.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,22 @@ | ||
package dev.latvian.mods.kubejs.block.entity; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface BlockEntityAttachment { | ||
BlockEntityAttachment[] EMPTY_ARRAY = new BlockEntityAttachment[0]; | ||
|
||
interface Factory { | ||
BlockEntityAttachment create(BlockEntityJS entity); | ||
} | ||
|
||
default CompoundTag writeAttachment() { | ||
return new CompoundTag(); | ||
} | ||
|
||
default void readAttachment(CompoundTag tag) { | ||
} | ||
|
||
default void onRemove(BlockState newState) { | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
common/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachmentHolder.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,8 @@ | ||
package dev.latvian.mods.kubejs.block.entity; | ||
|
||
public record BlockEntityAttachmentHolder(int index, BlockEntityAttachment.Factory factory) { | ||
@Override | ||
public String toString() { | ||
return "attachment_" + index; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
common/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityAttachmentType.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 dev.latvian.mods.kubejs.block.entity; | ||
|
||
import dev.latvian.mods.kubejs.typings.desc.ObjectDescJS; | ||
import dev.latvian.mods.kubejs.util.KubeJSPlugins; | ||
import dev.latvian.mods.kubejs.util.Lazy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public record BlockEntityAttachmentType(String type, ObjectDescJS input, Function<Map<String, Object>, BlockEntityAttachment.Factory> factory) { | ||
public static final Lazy<Map<String, BlockEntityAttachmentType>> ALL = Lazy.of(() -> { | ||
var map = new HashMap<String, BlockEntityAttachmentType>(); | ||
var list = new ArrayList<BlockEntityAttachmentType>(); | ||
KubeJSPlugins.forEachPlugin(p -> p.registerBlockEntityAttachments(list)); | ||
|
||
for (var type : list) { | ||
map.put(type.type, type); | ||
} | ||
|
||
return map; | ||
}); | ||
|
||
@Override | ||
public String toString() { | ||
return type; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityBuilder.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,26 @@ | ||
package dev.latvian.mods.kubejs.block.entity; | ||
|
||
import dev.latvian.mods.kubejs.registry.BuilderBase; | ||
import dev.latvian.mods.kubejs.registry.RegistryInfo; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
|
||
public class BlockEntityBuilder extends BuilderBase<BlockEntityType<?>> { | ||
public BlockEntityInfo info; | ||
|
||
public BlockEntityBuilder(ResourceLocation i, BlockEntityInfo info) { | ||
super(i); | ||
this.info = info; | ||
} | ||
|
||
@Override | ||
public RegistryInfo getRegistryType() { | ||
return RegistryInfo.BLOCK_ENTITY_TYPE; | ||
} | ||
|
||
@Override | ||
public BlockEntityType<?> createObject() { | ||
info.entityType = BlockEntityType.Builder.of(info::createBlockEntity, info.blockBuilder.get()).build(null); | ||
return info.entityType; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
common/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityCallback.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,5 @@ | ||
package dev.latvian.mods.kubejs.block.entity; | ||
|
||
public interface BlockEntityCallback { | ||
void accept(BlockEntityJS entity); | ||
} |
5 changes: 5 additions & 0 deletions
5
common/src/main/java/dev/latvian/mods/kubejs/block/entity/BlockEntityEventCallback.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,5 @@ | ||
package dev.latvian.mods.kubejs.block.entity; | ||
|
||
public interface BlockEntityEventCallback { | ||
void accept(BlockEntityJS entity, int data); | ||
} |
Oops, something went wrong.