first commit
This commit is contained in:
commit
d7fb0094fc
23 changed files with 1033 additions and 0 deletions
10
src/client/java/ovh/sad/snad/client/SnadClient.java
Normal file
10
src/client/java/ovh/sad/snad/client/SnadClient.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package ovh.sad.snad.client;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class SnadClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
}
|
||||
}
|
||||
14
src/client/resources/snad.client.mixins.json
Normal file
14
src/client/resources/snad.client.mixins.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "ovh.sad.snad.mixin.client",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"client": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"overwrites": {
|
||||
"requireAnnotations": true
|
||||
}
|
||||
}
|
||||
77
src/main/java/ovh/sad/snad/Snad.java
Normal file
77
src/main/java/ovh/sad/snad/Snad.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
package ovh.sad.snad;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
public class Snad implements ModInitializer {
|
||||
public static final String MOD_ID = "snad";
|
||||
private static Block register(String name, Function<AbstractBlock.Settings, Block> blockFactory, AbstractBlock.Settings settings, boolean shouldRegisterItem) {
|
||||
// Create a registry key for the block
|
||||
RegistryKey<Block> blockKey = keyOfBlock(name);
|
||||
// Create the block instance
|
||||
Block block = blockFactory.apply(settings.registryKey(blockKey));
|
||||
|
||||
// Sometimes, you may not want to register an item for the block.
|
||||
// Eg: if it's a technical block like `minecraft:moving_piston` or `minecraft:end_gateway`
|
||||
if (shouldRegisterItem) {
|
||||
// Items need to be registered with a different type of registry key, but the ID
|
||||
// can be the same.
|
||||
RegistryKey<Item> itemKey = keyOfItem(name);
|
||||
|
||||
BlockItem blockItem = new BlockItem(block, new Item.Settings().registryKey(itemKey).useBlockPrefixedTranslationKey());
|
||||
Registry.register(Registries.ITEM, itemKey, blockItem);
|
||||
}
|
||||
|
||||
return Registry.register(Registries.BLOCK, blockKey, block);
|
||||
}
|
||||
|
||||
private static RegistryKey<Block> keyOfBlock(String name) {
|
||||
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(Snad.MOD_ID, name));
|
||||
}
|
||||
|
||||
private static RegistryKey<Item> keyOfItem(String name) {
|
||||
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(Snad.MOD_ID, name));
|
||||
}
|
||||
|
||||
public static final Block SNAD_BLOCK = register(
|
||||
"snad",
|
||||
SnadBlock::new,
|
||||
AbstractBlock.Settings.create(),
|
||||
true
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register((itemGroup) -> {
|
||||
itemGroup.add(Snad.SNAD_BLOCK.asItem());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
80
src/main/java/ovh/sad/snad/SnadBlock.java
Normal file
80
src/main/java/ovh/sad/snad/SnadBlock.java
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package ovh.sad.snad;
|
||||
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.block.WireOrientation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SnadBlock extends Block {
|
||||
public static final BooleanProperty POWERED = Properties.POWERED;
|
||||
|
||||
public SnadBlock(Settings settings) {
|
||||
super(settings);
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(POWERED);
|
||||
}
|
||||
|
||||
private boolean isSugarCane(Block block) {
|
||||
Identifier id = Registries.BLOCK.getId(block);
|
||||
|
||||
if (id.equals(Identifier.of("minecraft", "sugar_cane"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// adds support for shiro's growable ores
|
||||
String path = id.getPath();
|
||||
if (id.getNamespace().equals("growable_ores") && path.endsWith("_cane")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void neighborUpdate(BlockState state, World world, BlockPos pos,
|
||||
Block sourceBlock, @Nullable WireOrientation wireOrientation, boolean notify) {
|
||||
super.neighborUpdate(state, world, pos, sourceBlock, wireOrientation, notify);
|
||||
if (world.isClient) return;
|
||||
|
||||
boolean hasPower = world.getReceivedRedstonePower(pos) > 0;
|
||||
boolean currentlyPowered = state.get(POWERED);
|
||||
|
||||
if (hasPower && !currentlyPowered) {
|
||||
world.setBlockState(pos, state.with(POWERED, true), Block.NOTIFY_LISTENERS);
|
||||
|
||||
BlockPos canePos = pos.up();
|
||||
BlockState caneState = world.getBlockState(canePos);
|
||||
Block cane = caneState.getBlock();
|
||||
|
||||
if (isSugarCane(cane)) {
|
||||
// 10% chance
|
||||
if (world.getRandom().nextFloat() < 0.10f) {
|
||||
BlockPos topPos = canePos;
|
||||
|
||||
while (isSugarCane(world.getBlockState(topPos.up()).getBlock())) {
|
||||
topPos = topPos.up();
|
||||
}
|
||||
|
||||
BlockPos newCanePos = topPos.up();
|
||||
if (world.getBlockState(newCanePos).isAir()) {
|
||||
world.setBlockState(newCanePos, caneState, Block.NOTIFY_LISTENERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!hasPower && currentlyPowered) {
|
||||
world.setBlockState(pos, state.with(POWERED, false), Block.NOTIFY_LISTENERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/main/resources/assets/snad/blockstates/snad.json
Normal file
7
src/main/resources/assets/snad/blockstates/snad.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "minecraft:block/sand"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/snad/icon.png
Normal file
BIN
src/main/resources/assets/snad/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
6
src/main/resources/assets/snad/items/snad.json
Normal file
6
src/main/resources/assets/snad/items/snad.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "minecraft:block/sand"
|
||||
}
|
||||
}
|
||||
3
src/main/resources/assets/snad/lang/en_us.json
Normal file
3
src/main/resources/assets/snad/lang/en_us.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"block.snad.snad": "Snad"
|
||||
}
|
||||
6
src/main/resources/assets/snad/models/block/snad.json
Normal file
6
src/main/resources/assets/snad/models/block/snad.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:block/cube_all",
|
||||
"textures": {
|
||||
"all": "minecraft:block/sand"
|
||||
}
|
||||
}
|
||||
6
src/main/resources/data/minecraft/tags/block/sand.json
Normal file
6
src/main/resources/data/minecraft/tags/block/sand.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"snad:snad"
|
||||
]
|
||||
}
|
||||
14
src/main/resources/data/snad/recipe/snad.json
Normal file
14
src/main/resources/data/snad/recipe/snad.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"#R"
|
||||
],
|
||||
"key": {
|
||||
"#": "minecraft:sand",
|
||||
"R": "minecraft:redstone"
|
||||
},
|
||||
"result": {
|
||||
"id": "snad:snad",
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||
33
src/main/resources/fabric.mod.json
Normal file
33
src/main/resources/fabric.mod.json
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "snad",
|
||||
"version": "${version}",
|
||||
"name": "Snad",
|
||||
"description": "Adds redstone activated sand, that grows cane that's on top of it. Doesn't work for cactus though, cause I hate how cactus spawns.",
|
||||
"authors": ["fucksophie"],
|
||||
"contact": {},
|
||||
"license": "All-Rights-Reserved",
|
||||
"icon": "assets/snad/icon.png",
|
||||
"environment": "*",
|
||||
"accessWidener" : "snad.accesswidener",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"ovh.sad.snad.client.SnadClient"
|
||||
],
|
||||
"main": [
|
||||
"ovh.sad.snad.Snad"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"snad.mixins.json",
|
||||
{
|
||||
"config": "snad.client.mixins.json",
|
||||
"environment": "client"
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric": "*",
|
||||
"minecraft": "${minecraft_version}"
|
||||
}
|
||||
}
|
||||
3
src/main/resources/snad.accesswidener
Normal file
3
src/main/resources/snad.accesswidener
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
accessWidener v2 named
|
||||
|
||||
accessible method net/minecraft/block/SugarCaneBlock randomTick (Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/random/Random;)V
|
||||
14
src/main/resources/snad.mixins.json
Normal file
14
src/main/resources/snad.mixins.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "ovh.sad.snad.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"overwrites": {
|
||||
"requireAnnotations": true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue