Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sforzando.legatolibrary.config;
- public class ConfigHandler {
- public static void readConfig (Path path, ConfigProfile profile) {
- File file = new File(path.toFile(), profile.getModID() + ".properties");
- profile.logger.info("Reading mod config state from file at: " + file.toString());
- if (!file.exists()) {
- profile.logger.error("Could not find file: " + file.toString());
- return;
- }
- try {
- Properties config = new Properties().load(new FileReader(file));
- for (String key : profile.keySet()) {
- if (config.getProperty(key) != null) {
- ConfigValues.setConfigValue(key, config.get(key));
- } else {
- profile.logger.error("Could not find key: " + key);
- }
- }
- } catch (IOFoundException var4) {
- profile.logger.error(var4);
- }
- }
- public static void writeConfig (Path path, ConfigProfile profile) {
- File file = new File(path.toFile(), profile.getModID() + ".properties");
- profile.logger.info("Writing mod config state to file at: " + file.toString());
- if (file.exists()) {
- try {
- file.delete();
- file.createNewFile();
- profile.logger.info("Cleared file at: " + file.toString());
- } catch (IOException ioe) {
- profile.logger.error("Could not clear file at: " + file.toString(), ioe);
- return;
- }
- } else {
- try {
- file.createNewFile();
- profile.logger.info("Created file at: " + file.toString());
- } catch (IOException ioe) {
- profile.logger.error("Could not create file at: " + file.toString(), ioe);
- return;
- }
- }
- try {
- Properties config = new Properties();
- for (String key : profile.keySet())
- config.setProperty(key, profile.get(key));
- config.store(new FileWriter(file), "Config settings for mod with ID: " + profile.getModID());
- } catch (IOFoundException var4) {
- profile.logger.error(var4);
- }
- }
- }
- public class ConfigProfile {
- public final Logger logger;
- private final String modID;
- private HashMap<String, String> properties = new HashMap<String, String>();
- public ConfigProfile (String id, Logger log) {
- this.modID = id;
- this.logger = log;
- }
- public String getModID () {
- return this.modID();
- }
- public Set<String> keySet () {
- return this.properties.keySet();
- }
- public String get (String key) {
- return this.properties.get(key);
- }
- }
- package com.sforzando.legatolibrary.items;
- public class ManagedInteractionItem extends Item {
- private final Interaction interaction;
- private final BlockInteraction bInteraction;
- public ManagedInteractionItem (Interaction i, BlockInteraction bi, Item.Settings settings) {
- super (settings);
- this.interaction = i;
- this.bInteraction = bi;
- }
- public ActionResult use (World world, PlayerEntity player, Hand hand) {
- return this.interaction.use(this, world, player, hand);
- }
- public ActionResult useOn (UseOnContext ctx) {
- return this.bInteraction.useOn(this, ctx);
- }
- public static interface Interaction {
- ActionResult use (Item item, World world, PlayerEntity player, Hand hand);
- static Interaction defaultInteraction () {
- return (i, w, p, h) -> {
- FoodComponent food = (FoodComponent)p.getItemInHand(h).get(DataComponents.FOOD);
- if (food != null) {
- if (p.canEat(food.canAlwaysEat())) {
- p.startUsingItem(h);
- return ActionResult.CONSUME;
- } else {
- return ActionResultHolder.FAIL;
- }
- } else {
- return ActionResult.PASS;
- }
- };
- }
- }
- public static interface BlockInteraction {
- ActionResult useOn (Item item, UseOnContext ctx);
- static BlockInteraction defaultInteraction () {
- return (i, c) -> { return ActionResult.PASS; };
- }
- }
- }
- public class EffectApplierSwordItem extends SwordItem {
- private final StatusEffectInstance effect;
- public EffectApplierSwordItem (StatusEffectInstance instance, ToolMaterial material, float damage, float speed, Item.Settings settings) {
- super (material, damage, speed, settings);
- this.effect = instance;
- }
- public boolean postHit (ItemStack item, LivingEntity target, LivingEntity attacker) {
- if (!super.postHit(item, target, attacker)) return false;
- target.addStatusEffect(this.effect, attacker);
- return true;
- }
- }
- public class EffectApplierPickaxeItem extends PickaxeItem {
- private final StatusEffectInstance effect;
- public EffectApplierPickaxeItem (StatusEffectInstance instance, ToolMaterial material, float damage, float speed, Item.Settings settings) {
- super (material, damage, speed, settings);
- this.effect = instance;
- }
- public boolean postHit (ItemStack item, LivingEntity target, LivingEntity attacker) {
- if (!super.postHit(item, target, attacker)) return false;
- target.addStatusEffect(this.effect, attacker);
- return true;
- }
- }
- public class EffectApplierAxeItem extends AxeItem {
- private final StatusEffectInstance effect;
- public EffectApplierAxeItem (StatusEffectInstance instance, ToolMaterial material, float damage, float speed, Item.Settings settings) {
- super (material, damage, speed, settings);
- this.effect = instance;
- }
- public boolean postHit (ItemStack item, LivingEntity target, LivingEntity attacker) {
- if (!super.postHit(item, target, attacker)) return false;
- target.addStatusEffect(this.effect, attacker);
- return true;
- }
- }
- public class EffectApplierShovelItem extends ShovelItem {
- private final StatusEffectInstance effect;
- public EffectApplierShovelItem (StatusEffectInstance instance, ToolMaterial material, float damage, float speed, Item.Settings settings) {
- super (material, damage, speed, settings);
- this.effect = instance;
- }
- public boolean postHit (ItemStack item, LivingEntity target, LivingEntity attacker) {
- if (!super.postHit(item, target, attacker)) return false;
- target.addStatusEffect(this.effect, attacker);
- return true;
- }
- }
- public class EffectApplierHoeItem extends HoeItem {
- private final StatusEffectInstance effect;
- public EffectApplierPickaxeItem (StatusEffectInstance instance, ToolMaterial material, float damage, float speed, Item.Settings settings) {
- super (material, damage, speed, settings);
- this.effect = instance;
- }
- public boolean postHit (ItemStack item, LivingEntity target, LivingEntity attacker) {
- if (!super.postHit(item, target, attacker)) return false;
- target.addStatusEffect(this.effect, attacker);
- return true;
- }
- }
- package com.sforzando.legatolibrary.blocks;
- public class ManagedInteractionBlock extends Block {
- private final Interaction interaction;
- private final ItemInteraction iInteraction;
- public ManagedInteractionBlock (Interaction i, ItemInteraction ii, AbstractBlock.Settings settings) {
- super (settings);
- this.interaction = i;
- this.iInteraction = ii;
- }
- public ActionResult onUse (BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
- return this.interaction.onUse(this, state, world, pos, player, hit);
- }
- public ActionResult onUseWithItem (ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
- return this.interaction.onUseWithItem(this, stack, state, world, pos, player, hand, hit);
- }
- public static interface Interaction {
- ActionResult onUse (Block block, BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit);
- static Interaction defaultInteraction () {
- return (b, s, w, p, e, h) -> { return InteractionResult.PASS; };
- }
- }
- public static interface ItemInteraction {
- ActionResult onUseWithItem (Block block, ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit);
- static ItemInteraction defaultInteraction () {
- return (b, s, w, p, e, h) -> { return ActionResult.PASS_TO_DEFAULT_BLOCK_ACTION; };
- }
- }
- }
- public class ShapedBlock extends Block {
- private final VoxelShape shape;
- private final boolean fullCube;
- public ShapedBlock (VoxelShape vs, boolean cube, AbstractBlock.Settings settings) {
- super (settings);
- this.shape = vs;
- this.fullCube = cube;
- }
- protected VoxelShape getRaycastShape (BlockState state, BlockView world, BlockPos pos) {
- return this.shape;
- }
- protected VoxelShape getOutlineShape (BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
- return this.shape;
- }
- protected VoxelShape getCollisionShape (BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
- return this.shape;
- }
- protected boolean isShapeFullCube (BlockState state, BlockView world, BlockPos pos) {
- return this.fullCube;
- }
- protected VoxelShape getCameraCollisionShape (BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
- return this.shape;
- }
- }
- public class ManagedInteractionAndShapeBlock extends Block {
- private final VoxelShape shape;
- private final boolean fullCube;
- private final ManagedInteractionBlock.Interaction interaction;
- private final ManagedInteractionBlock.ItemInteraction iInteraction;
- public ManagedInteractionAndShapeBlock (VoxelShape vs, boolean cube, ManagedInteractionBlock.Interaction i, ManagedInteractionBlock.ItemInteraction ii, AbstractBlock.Settings settings) {
- super (settings);
- this.shape = vs;
- this.fullCube = cube;
- this.interaction = i;
- this.iInteraction = ii;
- }
- public InteractionResult onUse (BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
- return this.interaction.onUse(this, state, world, pos, player, hit);
- }
- public InteractionResult onUseWithItem (ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
- return this.iInteraction.onUseWithItem(this, stack, state, world, pos, player, hand, hit);
- }
- protected VoxelShape getRaycastShape (BlockState state, BlockView world, BlockPos pos) {
- return this.shape;
- }
- protected VoxelShape getOutlineShape (BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
- return this.shape;
- }
- protected VoxelShape getCollisionShape (BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
- return this.shape;
- }
- protected boolean isShapeFullCube (BlockState state, BlockView world, BlockPos pos) {
- return this.fullCube;
- }
- protected VoxelShape getCameraCollisionShape (BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
- return this.shape;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement