Skip to content

Commit 7bf3582

Browse files
committed
stable version (i think)
1 parent 22b5277 commit 7bf3582

File tree

10 files changed

+136
-50
lines changed

10 files changed

+136
-50
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ org.gradle.jvmargs=-Xmx1G
99

1010
# Mod Properties
1111
mod_version = 1.0.0
12-
maven_group = com.example
13-
archives_base_name = fabric-example-mod
12+
maven_group = net.just_s
13+
archives_base_name = survival-debug-mod
1414

1515
# Dependencies
1616
fabric_version=0.55.1+1.19

src/main/java/net/fabricmc/example/ExampleMod.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/net/fabricmc/example/mixin/ExampleMixin.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.just_s.sds;
2+
3+
import net.fabricmc.api.ModInitializer;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
public class SDSMod implements ModInitializer {
8+
public static final Logger LOGGER = LoggerFactory.getLogger("sds");
9+
10+
@Override
11+
public void onInitialize() {
12+
LOGGER.info("SDS initialized successfully!");
13+
}
14+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package net.just_s.sds.mixin;
2+
3+
import net.minecraft.block.Block;
4+
import net.minecraft.block.BlockState;
5+
import net.minecraft.entity.player.PlayerEntity;
6+
import net.minecraft.item.DebugStickItem;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.nbt.NbtCompound;
9+
import net.minecraft.state.StateManager;
10+
import net.minecraft.state.property.Property;
11+
import net.minecraft.text.Text;
12+
import net.minecraft.util.math.BlockPos;
13+
import net.minecraft.util.registry.Registry;
14+
import net.minecraft.world.WorldAccess;
15+
import org.jetbrains.annotations.Nullable;
16+
import org.spongepowered.asm.mixin.Mixin;
17+
import org.spongepowered.asm.mixin.Shadow;
18+
import org.spongepowered.asm.mixin.injection.At;
19+
import org.spongepowered.asm.mixin.injection.Inject;
20+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
21+
22+
import java.util.Collection;
23+
24+
@Mixin(DebugStickItem.class)
25+
public class DebugStickMixin {
26+
27+
@Shadow
28+
private static void sendMessage(PlayerEntity player, Text message) {
29+
// shadowing for ease access
30+
}
31+
32+
@Shadow
33+
private static <T> T cycle(Iterable<T> elements, @Nullable T current, boolean inverse) {
34+
return null;
35+
}
36+
37+
@Shadow
38+
private static <T extends Comparable<T>> BlockState cycle(BlockState state, Property<T> property, boolean inverse) {
39+
return null;
40+
}
41+
42+
@Shadow
43+
private static <T extends Comparable<T>> String getValueString(BlockState state, Property<T> property) {
44+
return null;
45+
}
46+
47+
@Inject(at = @At("HEAD"), method = "use", cancellable = true)
48+
private void injectUse(PlayerEntity player, BlockState state, WorldAccess world, BlockPos pos, boolean update, ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
49+
if (!player.isCreativeLevelTwoOp()) {
50+
Block block = state.getBlock();
51+
if (
52+
block.getTranslationKey().contains("stairs") |
53+
block.getTranslationKey().contains("wall") |
54+
block.getTranslationKey().contains("fence") |
55+
block.getTranslationKey().contains("glass_pane") |
56+
block.getTranslationKey().contains("iron_bars"))
57+
{
58+
StateManager<Block, BlockState> stateManager = block.getStateManager();
59+
Collection<Property<?>> collection = stateManager.getProperties();
60+
String string = Registry.BLOCK.getId(block).toString();
61+
if (collection.isEmpty()) {
62+
sendMessage(player, Text.of("Невозможно преобразовать данный блок"));
63+
cir.setReturnValue(false);
64+
} else {
65+
NbtCompound nbtCompound = stack.getOrCreateSubNbt("DebugProperty");
66+
String string2 = nbtCompound.getString(string);
67+
Property<?> property = stateManager.getProperty(string2);
68+
if (!player.shouldCancelInteraction()) {
69+
if (property == null) {
70+
property = (Property)collection.iterator().next();
71+
}
72+
73+
if (property.getName().equals("waterlogged")) {
74+
property = (Property)cycle((Iterable)collection, (Object)property, false);
75+
}
76+
77+
BlockState blockState = cycle(state, property, false);
78+
world.setBlockState(pos, blockState, 18);
79+
sendMessage(player, Text.of("Параметр «" + property.getName() +"» изменён ("+ getValueString(blockState, property) + ")"));
80+
} else {
81+
property = (Property)cycle((Iterable)collection, (Object)property, false);
82+
if (property.getName().equals("waterlogged")) {
83+
property = (Property)cycle((Iterable)collection, (Object)property, false);
84+
}
85+
String string3 = property.getName();
86+
nbtCompound.putString(string, string3);
87+
sendMessage(player, Text.of("Параметр «" + string3 +"» выбран ("+ getValueString(state, property) + ")"));
88+
}
89+
90+
cir.setReturnValue(true);
91+
}
92+
} else {
93+
sendMessage(player, Text.of("Невозможно преобразовать данный блок"));
94+
cir.setReturnValue(false);
95+
}
96+
}
97+
}
98+
}
-453 Bytes
Binary file not shown.
24.3 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "minecraft:crafting_shapeless",
3+
"ingredients": [
4+
{"item": "minecraft:stick"},
5+
{"item": "minecraft:chorus_fruit"}
6+
],
7+
"result": {
8+
"count": 1,
9+
"item": "minecraft:debug_stick"
10+
}
11+
}

src/main/resources/fabric.mod.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
22
"schemaVersion": 1,
3-
"id": "modid",
3+
"id": "sds",
44
"version": "${version}",
55

6-
"name": "Example Mod",
7-
"description": "This is an example description! Tell everyone what your mod is about!",
6+
"name": "Survival Debug Stick Mod",
7+
"description": "This mod provides survival players with ability to create and use debug stick from creative inventory",
88
"authors": [
9-
"Me!"
9+
"Just_S"
1010
],
1111
"contact": {
12-
"homepage": "https://fabricmc.net/",
13-
"sources": "https://github.com/FabricMC/fabric-example-mod"
12+
"YouTube": "https://www.youtube.com/c/JustS_js",
13+
"sources": "https://github.com/JustS-js/debugStickSurvival"
1414
},
1515

1616
"license": "CC0-1.0",
17-
"icon": "assets/modid/icon.png",
17+
"icon": "assets/sds/icon.png",
1818

1919
"environment": "*",
2020
"entrypoints": {
2121
"main": [
22-
"net.fabricmc.example.ExampleMod"
22+
"net.just_s.sds.SDSMod"
2323
]
2424
},
2525
"mixins": [
26-
"modid.mixins.json"
26+
"sds.mixins.json"
2727
],
2828

2929
"depends": {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"required": true,
33
"minVersion": "0.8",
4-
"package": "net.fabricmc.example.mixin",
4+
"package": "net.just_s.sds.mixin",
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
7+
"DebugStickMixin"
78
],
89
"client": [
9-
"ExampleMixin"
1010
],
1111
"injectors": {
1212
"defaultRequire": 1

0 commit comments

Comments
 (0)