Added a configuration screen; bumped version
This commit is contained in:
		
							parent
							
								
									55a8fbef43
								
							
						
					
					
						commit
						8bdffdb09f
					
				
					 8 changed files with 80 additions and 35 deletions
				
			
		
							
								
								
									
										11
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								build.gradle
									
									
									
									
									
								
							| 
						 | 
					@ -11,24 +11,13 @@ version = project.mod_version
 | 
				
			||||||
group = project.maven_group
 | 
					group = project.maven_group
 | 
				
			||||||
 | 
					
 | 
				
			||||||
repositories {
 | 
					repositories {
 | 
				
			||||||
	// Add repositories to retrieve artifacts from in here.
 | 
					 | 
				
			||||||
	// You should only use this when depending on other mods because
 | 
					 | 
				
			||||||
	// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
 | 
					 | 
				
			||||||
	// See https://docs.gradle.org/current/userguide/declaring_repositories.html
 | 
					 | 
				
			||||||
	// for more information about repositories.
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dependencies {
 | 
					dependencies {
 | 
				
			||||||
	// To change the versions see the gradle.properties file
 | 
					 | 
				
			||||||
	minecraft "com.mojang:minecraft:${project.minecraft_version}"
 | 
						minecraft "com.mojang:minecraft:${project.minecraft_version}"
 | 
				
			||||||
	mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
 | 
						mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
 | 
				
			||||||
	modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
 | 
						modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Fabric API. This is technically optional, but you probably want it anyway.
 | 
					 | 
				
			||||||
	modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
 | 
						modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
 | 
					 | 
				
			||||||
	// You may need to force-disable transitiveness on them.
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
processResources {
 | 
					processResources {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,13 +2,12 @@
 | 
				
			||||||
org.gradle.jvmargs=-Xmx1G
 | 
					org.gradle.jvmargs=-Xmx1G
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Fabric Properties
 | 
					# Fabric Properties
 | 
				
			||||||
	# check these on https://fabricmc.net/versions.html
 | 
					 | 
				
			||||||
	minecraft_version=1.17.1
 | 
						minecraft_version=1.17.1
 | 
				
			||||||
	yarn_mappings=1.17.1+build.39
 | 
						yarn_mappings=1.17.1+build.39
 | 
				
			||||||
	loader_version=0.11.6
 | 
						loader_version=0.11.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Mod Properties
 | 
					# Mod Properties
 | 
				
			||||||
	mod_version = 1.0.1
 | 
						mod_version = 1.0.2
 | 
				
			||||||
	maven_group = dk.palmoe
 | 
						maven_group = dk.palmoe
 | 
				
			||||||
	archives_base_name = immersivexp
 | 
						archives_base_name = immersivexp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										63
									
								
								src/main/java/dk/palmoe/immersivexp/Config.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/main/java/dk/palmoe/immersivexp/Config.java
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,63 @@
 | 
				
			||||||
 | 
					package dk.palmoe.immersivexp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.io.FileReader;
 | 
				
			||||||
 | 
					import java.io.FileWriter;
 | 
				
			||||||
 | 
					import java.io.Reader;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gson.Gson;
 | 
				
			||||||
 | 
					import com.google.gson.stream.JsonWriter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.commons.io.IOUtils;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class Config {
 | 
				
			||||||
 | 
					    public int logBaseXP = 1;
 | 
				
			||||||
 | 
					    public int logRandXP = 2;
 | 
				
			||||||
 | 
					    public int cropBaseXP = 1;
 | 
				
			||||||
 | 
					    public int cropRandXP = 1;
 | 
				
			||||||
 | 
					    public int berriesBaseXP = 0;
 | 
				
			||||||
 | 
					    public int berriesRandXP = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static final File FILE = new File("config/immersivexp.json");
 | 
				
			||||||
 | 
					    public static Config INSTANCE = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static Config getInstance() {
 | 
				
			||||||
 | 
					        if (INSTANCE == null) {
 | 
				
			||||||
 | 
					            INSTANCE = new Config().read();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return INSTANCE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Config read() {
 | 
				
			||||||
 | 
					        if (!FILE.exists())
 | 
				
			||||||
 | 
					            return new Config().write();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Reader reader = null;
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            return new Gson().fromJson(reader = new FileReader(FILE), Config.class);
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					            throw new RuntimeException(e);
 | 
				
			||||||
 | 
					        } finally {
 | 
				
			||||||
 | 
					            IOUtils.closeQuietly(reader);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Config write() {
 | 
				
			||||||
 | 
					        Gson gson = new Gson();
 | 
				
			||||||
 | 
					        JsonWriter writer = null;
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            writer = gson.newJsonWriter(new FileWriter(FILE));
 | 
				
			||||||
 | 
					            writer.setIndent("    ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            gson.toJson(gson.toJsonTree(this, Config.class), writer);
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            ImmersiveXP.LOGGER.error("Couldn't save config");
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					            throw new RuntimeException(e);
 | 
				
			||||||
 | 
					        } finally {
 | 
				
			||||||
 | 
					            IOUtils.closeQuietly(writer);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,6 @@ import net.minecraft.block.CropBlock;
 | 
				
			||||||
import net.minecraft.block.MelonBlock;
 | 
					import net.minecraft.block.MelonBlock;
 | 
				
			||||||
import net.minecraft.block.SweetBerryBushBlock;
 | 
					import net.minecraft.block.SweetBerryBushBlock;
 | 
				
			||||||
import net.minecraft.server.world.ServerWorld;
 | 
					import net.minecraft.server.world.ServerWorld;
 | 
				
			||||||
import net.minecraft.state.property.Property;
 | 
					 | 
				
			||||||
import net.minecraft.tag.BlockTags;
 | 
					import net.minecraft.tag.BlockTags;
 | 
				
			||||||
import net.minecraft.util.ActionResult;
 | 
					import net.minecraft.util.ActionResult;
 | 
				
			||||||
import net.minecraft.util.Identifier;
 | 
					import net.minecraft.util.Identifier;
 | 
				
			||||||
| 
						 | 
					@ -16,10 +15,10 @@ import net.minecraft.util.registry.Registry;
 | 
				
			||||||
public class Events {
 | 
					public class Events {
 | 
				
			||||||
    public static void init() {
 | 
					    public static void init() {
 | 
				
			||||||
        PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, entity) -> {
 | 
					        PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, entity) -> {
 | 
				
			||||||
            // TODO: Make experience amount configurable
 | 
					 | 
				
			||||||
            if (world instanceof ServerWorld) {
 | 
					            if (world instanceof ServerWorld) {
 | 
				
			||||||
                if (state.getBlock() instanceof CropBlock || state.getBlock() instanceof MelonBlock) {
 | 
					                if (state.getBlock() instanceof CropBlock || state.getBlock() instanceof MelonBlock) {
 | 
				
			||||||
                    Util.spawnExp((ServerWorld) world, pos, 1, 1);
 | 
					                    Config config = Config.getInstance();
 | 
				
			||||||
 | 
					                    Util.spawnXp((ServerWorld) world, pos, config.cropBaseXP, config.cropRandXP);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (state.isIn(BlockTags.LOGS)) {
 | 
					                if (state.isIn(BlockTags.LOGS)) {
 | 
				
			||||||
| 
						 | 
					@ -27,20 +26,22 @@ public class Events {
 | 
				
			||||||
                    boolean isGrown = Util.isTreeNaturallyGrown(world, pos);
 | 
					                    boolean isGrown = Util.isTreeNaturallyGrown(world, pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (holdingAxe && isGrown) {
 | 
					                    if (holdingAxe && isGrown) {
 | 
				
			||||||
                        Util.spawnExp((ServerWorld) world, pos, 1, 4);
 | 
					                        Config config = Config.getInstance();
 | 
				
			||||||
 | 
					                        Util.spawnXp((ServerWorld) world, pos, config.logBaseXP, config.logRandXP);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        UseBlockCallback.EVENT.register(((player, world, hand, hitResult) -> {
 | 
					        UseBlockCallback.EVENT.register(((player, world, hand, hitResult) -> {
 | 
				
			||||||
            // TODO: Make experience amount configurable
 | 
					 | 
				
			||||||
            BlockState state = world.getBlockState(hitResult.getBlockPos());
 | 
					            BlockState state = world.getBlockState(hitResult.getBlockPos());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (state.getBlock() instanceof SweetBerryBushBlock && world instanceof ServerWorld) {
 | 
					            if (state.getBlock() instanceof SweetBerryBushBlock && world instanceof ServerWorld) {
 | 
				
			||||||
                int age = state.get(SweetBerryBushBlock.AGE);
 | 
					                int age = state.get(SweetBerryBushBlock.AGE);
 | 
				
			||||||
                if (age == 3) {
 | 
					                if (age == 3) {
 | 
				
			||||||
                    Util.spawnExp((ServerWorld) world, hitResult.getBlockPos(), 1, 1);
 | 
					                    Config config = Config.getInstance();
 | 
				
			||||||
 | 
					                    Util.spawnXp((ServerWorld) world, hitResult.getBlockPos(), config.berriesBaseXP,
 | 
				
			||||||
 | 
					                            config.berriesRandXP);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,8 +39,8 @@ public class Util {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void spawnExp(ServerWorld world, BlockPos pos, int min, int cap) {
 | 
					    public static void spawnXp(ServerWorld world, BlockPos pos, int min, int cap) {
 | 
				
			||||||
        Vec3d exp_pos = new Vec3d(pos.getX(), pos.getY(), pos.getZ());
 | 
					        Vec3d xp_pos = new Vec3d(pos.getX(), pos.getY(), pos.getZ());
 | 
				
			||||||
        ExperienceOrbEntity.spawn(world, exp_pos, min + world.random.nextInt(cap));
 | 
					        ExperienceOrbEntity.spawn(world, xp_pos, min + world.random.nextInt(cap));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +0,0 @@
 | 
				
			||||||
package dk.palmoe.immersivexp.mixin;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.spongepowered.asm.mixin.Mixin;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.minecraft.client.gui.screen.TitleScreen;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@Mixin(TitleScreen.class)
 | 
					 | 
				
			||||||
public class ImmersiveXPMixin {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@
 | 
				
			||||||
	"entrypoints": {
 | 
						"entrypoints": {
 | 
				
			||||||
		"main": ["dk.palmoe.immersivexp.ImmersiveXP"]
 | 
							"main": ["dk.palmoe.immersivexp.ImmersiveXP"]
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	"mixins": ["immersivexp.mixins.json"],
 | 
						"mixins": [],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"depends": {
 | 
						"depends": {
 | 
				
			||||||
		"fabricloader": ">=0.11.3",
 | 
							"fabricloader": ">=0.11.3",
 | 
				
			||||||
| 
						 | 
					@ -28,5 +28,8 @@
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	"suggests": {
 | 
						"suggests": {
 | 
				
			||||||
		"another-mod": "*"
 | 
							"another-mod": "*"
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"custom": {
 | 
				
			||||||
 | 
							"modmenu": {}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,8 @@
 | 
				
			||||||
	"minVersion": "0.8",
 | 
						"minVersion": "0.8",
 | 
				
			||||||
	"package": "dk.palmoe.immersivexp.mixin",
 | 
						"package": "dk.palmoe.immersivexp.mixin",
 | 
				
			||||||
	"compatibilityLevel": "JAVA_16",
 | 
						"compatibilityLevel": "JAVA_16",
 | 
				
			||||||
	"mixins": ["ImmersiveXPMixin"],
 | 
						"mixins": [],
 | 
				
			||||||
	"client": ["ImmersiveXPMixin"],
 | 
						"client": [],
 | 
				
			||||||
	"injectors": {
 | 
						"injectors": {
 | 
				
			||||||
		"defaultRequire": 1
 | 
							"defaultRequire": 1
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue