Updated implementation of most things. Switched to a working config file. Fixed config changing proxy'd jumpvader block to incorrect types. Added an "ENABLE" config option.
This commit is contained in:
@@ -3,86 +3,41 @@ package dev.venomcode.jumpvader;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ConfigSerializable
|
||||
public class JumpVaderConfig
|
||||
{
|
||||
|
||||
public boolean getEnabled()
|
||||
{
|
||||
return rootNode.node(ENABLED_TAG).getBoolean(true);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public int getMaxVerticalBlocks()
|
||||
{
|
||||
return rootNode.node(MAX_VERTICAL_BLOCKS_TAG).getInt(128);
|
||||
return maxVerticleBlocks;
|
||||
}
|
||||
public String getAlternativeBlock()
|
||||
{
|
||||
return rootNode.node(USE_ALTERNATIVE_BLOCK_TAG).getString("default");
|
||||
return placeholderBlockRaw;
|
||||
}
|
||||
|
||||
public void setupConfig() throws SerializationException
|
||||
{
|
||||
rootNode.node(ENABLED_TAG).comment(ENABLED_TAG_COMMENT).set(getEnabled());
|
||||
rootNode.node(MAX_VERTICAL_BLOCKS_TAG).comment(MAX_VERTICAL_BLOCKS_TAG_COMMENT).set(getMaxVerticalBlocks());
|
||||
rootNode.node(USE_ALTERNATIVE_BLOCK_TAG).comment(USE_ALTERNATIVE_BLOCK_TAG_COMMENT).set(getAlternativeBlock());
|
||||
@Setting("mod enabled")
|
||||
@Comment("Toggles the entire mod on/off. Doesnt delete blocks/items if set to off!")
|
||||
private boolean enabled = true;
|
||||
|
||||
save();
|
||||
}
|
||||
@Setting("max vertical blocks")
|
||||
@Comment("The maximum amount of blocks a player can move vertically using the jump vader")
|
||||
private int maxVerticleBlocks = 128;
|
||||
|
||||
// NODE LOCATION TAGS & COMMENTS
|
||||
private static final String ENABLED_TAG = "enabled";
|
||||
private static final String ENABLED_TAG_COMMENT = "Toggles this entire mod on and off.";
|
||||
private static final String MAX_VERTICAL_BLOCKS_TAG = "max_blocks_vertical";
|
||||
private static final String MAX_VERTICAL_BLOCKS_TAG_COMMENT = "The maximum amount of vertical blocks to travel when using the jump vader block.";
|
||||
private static final String USE_ALTERNATIVE_BLOCK_TAG = "use_alternative_block";
|
||||
private static final String USE_ALTERNATIVE_BLOCK_TAG_COMMENT = "Block to use for clients. Allowed Values: default, stained_glass, white_wool";
|
||||
|
||||
|
||||
public JumpVaderConfig()
|
||||
{
|
||||
loader = HoconConfigurationLoader.builder()
|
||||
.path(Path.of("./config/" + JumpVaderMod.MODID + ".conf"))
|
||||
.build();
|
||||
try
|
||||
{
|
||||
rootNode = loader.load();
|
||||
setupConfig();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
JumpVaderMod.LOGGER.info("Error occurred loading config:" + ex.getMessage());
|
||||
if(ex.getCause() != null)
|
||||
{
|
||||
ex.getCause().printStackTrace();
|
||||
}
|
||||
rootNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean save()
|
||||
{
|
||||
try
|
||||
{
|
||||
loader.save(rootNode);
|
||||
return true;
|
||||
}
|
||||
catch (final ConfigurateException ex)
|
||||
{
|
||||
JumpVaderMod.LOGGER.info("Unable to save config for '" + JumpVaderMod.MODID + "'! Error: " + ex.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private CommentedConfigurationNode getRootNode()
|
||||
{
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
private final HoconConfigurationLoader loader;
|
||||
private CommentedConfigurationNode rootNode;
|
||||
@Setting("display block")
|
||||
@Comment("Sets the 'fake' block to display as a placeholder for the jump vader block.")
|
||||
private String placeholderBlockRaw = "minecraft:orange_wool";
|
||||
}
|
||||
|
@@ -1,17 +1,27 @@
|
||||
package dev.venomcode.jumpvader;
|
||||
|
||||
import dev.venomcode.jumpvader.blocks.JumpVaderBlock;
|
||||
import dev.venomcode.serverapi.api.ServerAPI;
|
||||
import dev.venomcode.serverapi.api.event.SAPIPlayerEvents;
|
||||
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class JumpVaderMod implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
@@ -19,20 +29,76 @@ public class JumpVaderMod implements ModInitializer {
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final String MODID = "jumpvader";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);
|
||||
private static JumpVaderConfig config;
|
||||
|
||||
@Override
|
||||
public void onInitialize()
|
||||
{
|
||||
config = new JumpVaderConfig();
|
||||
JumpVaderConfig config = getConfig();
|
||||
saveConfig();
|
||||
|
||||
Identifier jumpVaderProxyIdent = new Identifier(config.getAlternativeBlock());
|
||||
Item jumpVaderProxyItem = Registries.ITEM.get(jumpVaderProxyIdent);
|
||||
|
||||
JUMP_VADER_BLOCK = new JumpVaderBlock(FabricBlockSettings.copyOf(Blocks.BAMBOO_PLANKS), Registries.BLOCK.get(jumpVaderProxyIdent));
|
||||
|
||||
Registry.register(Registries.BLOCK, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), JUMP_VADER_BLOCK);
|
||||
|
||||
Registry.register( Registries.ITEM, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), new PolymerBlockItem( JUMP_VADER_BLOCK, new FabricItemSettings(), Items.ORANGE_STAINED_GLASS ) );
|
||||
Registry.register( Registries.ITEM, new Identifier(JumpVaderMod.MODID, "jumpvader_block"), new PolymerBlockItem( JUMP_VADER_BLOCK, new FabricItemSettings(), jumpVaderProxyItem ) );
|
||||
|
||||
SAPIPlayerEvents.JUMP.register((player -> {
|
||||
if(!config.getEnabled())
|
||||
return true;
|
||||
BlockPos testPos = player.getBlockPos().down();
|
||||
if(player.getWorld().getBlockState(testPos).getBlock() instanceof JumpVaderBlock jumpVaderBlock)
|
||||
{
|
||||
return !jumpVaderBlock.onJump(testPos, player);
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
|
||||
SAPIPlayerEvents.SNEAK.register((player -> {
|
||||
if(!config.getEnabled())
|
||||
return true;
|
||||
|
||||
BlockPos testPos = player.getBlockPos().down();
|
||||
if(player.getWorld().getBlockState(testPos).getBlock() instanceof JumpVaderBlock jumpVaderBlock) {
|
||||
jumpVaderBlock.onCrouch(testPos, player);
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
public static JumpVaderConfig getConfig()
|
||||
{
|
||||
return config;
|
||||
public static JumpVaderBlock JUMP_VADER_BLOCK;
|
||||
|
||||
public static JumpVaderConfig getConfig() {
|
||||
if(_configCached != null)
|
||||
return _configCached;
|
||||
|
||||
try {
|
||||
CommentedConfigurationNode node = configLoader.load();
|
||||
|
||||
_configCached = node.get(JumpVaderConfig.class);
|
||||
}
|
||||
catch (ConfigurateException ex) {
|
||||
LOGGER.error(ServerAPI.Logger.Error("[ERROR]Failed to load jump_vader config."));
|
||||
}
|
||||
|
||||
return _configCached;
|
||||
}
|
||||
public static final JumpVaderBlock JUMP_VADER_BLOCK = new JumpVaderBlock(FabricBlockSettings.copyOf(Blocks.BAMBOO_PLANKS), Blocks.ORANGE_STAINED_GLASS);
|
||||
|
||||
public static void saveConfig() {
|
||||
CommentedConfigurationNode node = CommentedConfigurationNode.root();
|
||||
try {
|
||||
node.set(JumpVaderConfig.class, _configCached);
|
||||
configLoader.save(node);
|
||||
}
|
||||
catch (ConfigurateException ex) {
|
||||
LOGGER.error(ServerAPI.Logger.Error("[ERROR]Failed to save jump_vader config."));
|
||||
}
|
||||
}
|
||||
|
||||
private static final HoconConfigurationLoader configLoader = HoconConfigurationLoader.builder()
|
||||
.path(Path.of(ServerAPI.CONFIG_PATH + "jump_vader.conf"))
|
||||
.build();
|
||||
private static JumpVaderConfig _configCached = null;
|
||||
}
|
||||
|
@@ -90,15 +90,5 @@ public class JumpVaderBlock extends SimplePolymerBlock implements IJumpVaderList
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getPolymerBlock(BlockState state)
|
||||
{
|
||||
return switch (JumpVaderMod.getConfig().getAlternativeBlock()) {
|
||||
case "tinted_glass" -> Blocks.TINTED_GLASS;
|
||||
case "white_wool" -> Blocks.WHITE_WOOL;
|
||||
default -> Blocks.ORANGE_STAINED_GLASS;
|
||||
};
|
||||
}
|
||||
|
||||
private static final Identifier _identifier = new Identifier( JumpVaderMod.MODID, "jumpvader_block" );
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package dev.venomcode.jumpvader.mixin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import dev.venomcode.jumpvader.ifaces.IJumpVaderListener;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.encryption.PlayerPublicKey;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin( ServerPlayerEntity.class )
|
||||
public abstract class ServerPlayerMixin extends PlayerEntity
|
||||
{
|
||||
@Override
|
||||
public void jump( )
|
||||
{
|
||||
BlockPos p = this.getBlockPos().down();
|
||||
Block blk = this.world.getBlockState( p ).getBlock();
|
||||
|
||||
if(blk instanceof IJumpVaderListener bActioner)
|
||||
{
|
||||
if(bActioner.onJump( p, (ServerPlayerEntity ) (Object)this ))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.jump( );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSneaking( boolean sneaking )
|
||||
{
|
||||
super.setSneaking( sneaking );
|
||||
if(sneaking)
|
||||
{
|
||||
BlockPos p = this.getBlockPos().down();
|
||||
Block blk = this.world.getBlockState( p ).getBlock();
|
||||
|
||||
if(blk instanceof IJumpVaderListener bActioner)
|
||||
{
|
||||
bActioner.onCrouch( p, (ServerPlayerEntity ) (Object)this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ServerPlayerMixin(World world , BlockPos pos , float yaw , GameProfile profile, PlayerPublicKey pubKey)
|
||||
{
|
||||
super(world, pos, yaw, profile, pubKey);
|
||||
}
|
||||
}
|
@@ -4,7 +4,6 @@
|
||||
"package": "dev.venomcode.jumpvader.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ServerPlayerMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
Reference in New Issue
Block a user