Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

craytona

Members
  • Joined

  • Last visited

  1. I have a JSON file with a bunch of objects in it with values that I need to read. How would I go about being able to read this file and access the values. I understand that I need to use GSON but here are my issues. 1. How do I register the file pathway because it does now like using the qualified name. Also is my JSON Reader created correctly? public class GSONDamageResistanceReader { public static void Init() { String file = "/DungeonCraft/src/main/resources/data/dungeoncraft/tags/items/armor_damage_type_resistance_values.json"; //bad file path Gson gson = new GsonBuilder().create(); try (Reader reader = new FileReader(file)) { ArmorResistance armor = gson.fromJson(reader, ArmorResistance.class); System.out.println(armor); } catch (IOException e) { e.printStackTrace(); } } } 2. this is a sample of my JSON file to read and the values I need to get are the resistances. Would I need to store these objects in an array and then use my ArmorResistance class to set and get the values? { "minecraft:leather_chestplate": { "slashing_resistance" : 1, "piercing_resistance" : 1, "bludgeoning_resistance" : 1 }, "minecraft:leather_leggings": { "slashing_resistance" : 1, "piercing_resistance" : 1, "bludgeoning_resistance" : 1 } } Thanks in advance for the help. If you need anymore information let me know, been stuck on this for a while and cant find much else to help.
  2. craytona joined the community
  3. I am attempting to detect when a mob hits something and then check to see if the Entity is listed in an external file.I am wondering how I would do this. This is what I have currently got, Detect Entity attacking: //Mob attacking @SubscribeEvent public static void testEntityEvent(LivingHurtEvent event) { DamageSource damageSource = event.getSource(); if (damageSource.getTrueSource() instanceof MobEntity) { Item air = Item.getItemByID(0); LivingEntity livingEntity = (LivingEntity) damageSource.getTrueSource(); ItemStack stack = livingEntity.getHeldItemMainhand(); Item item = stack.getItem(); if (item != air) { System.out.println(DamageType.getFromItem(item)); } else { EntityType<?> entity = damageSource.getTrueSource().getEntity(); System.out.println(DamageType.getFromEntity(entity)); } } This is how I check DamageType: @Nonnull public static DamageType getFromEntity(EntityType<?> entity) { if (slashingDamageEntities.contains(entity)) { return SLASHING; } else if (piercingDamageEntities.contains(entity)) { return PIERCING; } return BLUDGEONING; } And this is how I register the Resource Location: public static final EntityTypeTags.Wrapper slashingDamageEntities = new EntityTypeTags.Wrapper(new ResourceLocation(dungeoncraft.MOD_ID, "slashing_damage_mobs")); public static final EntityTypeTags.Wrapper piercingDamageEntities = new EntityTypeTags.Wrapper(new ResourceLocation(dungeoncraft.MOD_ID, "piercing_damage_mobs")); Now I am aware that I am checking the Tags for EntityType<?> instead of Entity but I am wondering how to do it using an Entity instead. Or a better way to do it using EntityType<?> by modifying the first file. For reference this is my Tags file and the other is very similar. { "replace": false, "values": [ "minecraft:chicken", "minecraft:fox", "minecraft:parrot", "minecraft:pufferfish", "minecraft:turtle", "minecraft:bee", "minecraft:wolf", "minecraft:cave_spider", "minecraft:spider", "minecraft:elder_guardian", "minecraft:endermite", "minecraft:guardian", "minecraft:phantom", "minecraft:shulker", "minecraft:silverfish" ] }

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.