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.

CrackedScreen

Members
  • Joined

  • Last visited

Everything posted by CrackedScreen

  1. Wrote the following code and passed the serializer through a deferred register: public class ModLoot extends LootModifier { protected ModLoot(LootItemCondition[] conditionsIn) { super(conditionsIn); } @NotNull @Override protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) { generatedLoot.add(new ItemStack(Items.NETHERITE_SCRAP)); return generatedLoot; } public static class ModLootSerializer extends GlobalLootModifierSerializer<ModLoot> { @Override public ModLoot read(ResourceLocation location, JsonObject object, LootItemCondition[] ailootcondition) { return new ModLoot(ailootcondition); } @Override public JsonObject write(ModLoot instance) { return new JsonObject(); } } } Assuming any of this even works in the first place, what would a reliable way to test if the netherite scrap appears in loot chests? Currently using a seed which contains a broken nether portal next to spawn, but the contents are the same across recreating the world.
  2. I'm looking for the best way to add an item to existing chest loot tables without completely overwriting them, through an existing method (preferable) or from an event handler if necessary. Thanks in advance.
  3. public static final DeferredRegister<Item> ARMOR = DeferredRegister.create(ForgeRegistries.ITEMS, "minecraft"); Found it. Thanks for helping, will mark this thread as solved.
  4. What part of my code would I need to change in my original post in order for this to work? An example would help here, and if I need the full path of blocks/items to override then where can I find this?
  5. Does this mean I need to use a different method of registering, or that the full resource location of vanilla leather armor needs to be provided? I have tried setting the name to item.minecraft.leather_helmet, but this still generates a separate item. Using setRegistryname will cause a different crash as well.
  6. ResourceLocationException: net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location I'll need the correct syntax for alias usage since registering the item as minecraft:leather_helmet is causing this.
  7. I'm trying to override existing armor using the following: public static final RegistryObject<Item> LEATHER_HELMET = ITEMS.register("minecraft:leather_helmet", () -> new ModArmor(ArmorMaterials.LEATHER, EquipmentSlot.HEAD, (new Item.Properties()).tab(CreativeModeTab.TAB_COMBAT))); This causes the game client to crash, and the only other examples of alias usage I can find are from 1.16 or earlier. What's the correct implementation for 1.18?
  8. DamageItem works fine, but doesn't account for durability loss cancelled by Unbreaking enchantments. Is this something I will need to handle myself, or are there other accessible fields I can use inside this method?
  9. Is there a method in 1.18.X to check when an armor item takes damage within it's own class? In 1.16.5 I remember seeing damageArmor() override or something similar accessible by classes extended from ItemArmor which served this purpose. I am also looking for a way to get the durability loss caused by a damage source. If this is possible (from either inside armor class or event), does it take the Unbreaking enchantment into account? Thanks in advance.
  10. Looks like I'll just use hardcoded checks or create my own tag to handle all the ores. Thanks for answering.
  11. The ORES tag doesn't seem to include any of the deepslate or copper ore variants, so I'd have to go through specific use cases which I'd prefer to avoid. Are there any other ways to check that I'm not aware of, or are hard coded/messy generic checks (such as "ore" in block name") the only alternative ways?
  12. I understand Oredict was discontinued in older versions of forge and replaced with Tags. What is the current best way to detect if a block is an ore, and is there a way to account for ores added by other mods as well?
  13. 1. Looking at some older forum posts there is a mention of builtin methods that would handle getting a list of blocks in a radius such as getAllInBox(), though this seems to be absent from 1.18.1 as I have searched through BlockPos and Block classes. Are there any replacements for these methods in the current Forge version? 2. What is the "proper" way to check the number of ticks a block has been placed for and remove it afterwards?
  14. Seems to be fixed after adding checks where they might be needed. Marking this as solved.
  15. Currently getting a TickingEntity crash from usage of getDistance() in this method, occurs frequently when my projectile entity hits another entity: @Override protected void onHitEntity(EntityHitResult hitResult) { LivingEntity target = (LivingEntity) hitResult.getEntity(); Entity shooter = getOwner(); System.out.println("HIT"); System.out.println("DISTANCE: " + Objects.requireNonNull(getOwner()).distanceTo(target)); double armor = target.getArmorValue() * (1 - piercing); double toughness = Objects.requireNonNull(target.getAttribute(Attributes.ARMOR_TOUGHNESS)).getValue(); float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25)); target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage); if (bulletType == BulletType.COPPER) { target.invulnerableTime = 0; } } Full code here: https://github.com/CrackedScreen/Mod_1.18 Error log:
  16. Thanks for helping. Marking this thread as solved.
  17. Fixed the spawn location problem, though the Item texture override I specified in my BulletRenderer isn't being used. Is it possible to override entity textures when extending from ThrownItemRenderer, or will I have to create an entirely new renderer from scratch?
  18. I remember prints indicating which thread they come from previously but not anymore, that might have something to do with it. Uploaded code here: https://github.com/CrackedScreen/Mod_1.18
  19. Bumping topic again, as I have gotten the projectile to register properly and even print out the amount of ticks it is alive, yet doesn't "spawn" in the world when it should be. Spawning code: @Override public void createProjectile(Player player, Level level, ItemStack stack) { int pierceLevel = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.FIREPOWER, stack); if (!level.isClientSide) { BulletEntity bullet = new BulletEntity(level, getDamage(), pierceLevel); bullet.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F); level.addFreshEntity(bullet); } } BulletEntity: public class BulletEntity extends ThrowableItemProjectile { private float damage = 12.0F; private int pierceLevel = 0; private int ticksAlive = 0; private final int lifespan = 60; public BulletEntity(EntityType<? extends BulletEntity> type, Level level) { super(type, level); } public BulletEntity(Level level, float damage, int pierceLevel) { super(ExampleMod.BULLET.get(), level); this.damage = damage; this.pierceLevel = pierceLevel; this.setNoGravity(true); } public DamageSource causeBulletDamage(BulletEntity bullet, Entity attacker) { return (new IndirectEntityDamageSource("bullet", bullet, attacker)).setProjectile(); } public void tick() { super.tick(); Vec3 vec3d = this.getDeltaMovement(); double d1 = vec3d.x; double d2 = vec3d.y; double d0 = vec3d.z; if (this.isInWater()) { this.level.addParticle(ParticleTypes.BUBBLE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } else { this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } if (ticksAlive > lifespan) { this.discard(); } ticksAlive++; } @Override protected void onHitEntity(EntityHitResult hitResult) { LivingEntity target = (LivingEntity) hitResult.getEntity(); Entity shooter = getOwner(); double armor = target.getArmorValue() * (1 - (0.2 * pierceLevel)); double toughness = target.getAttribute(Attributes.ARMOR_TOUGHNESS).getValue(); float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25)); target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage); } @Override public Item getDefaultItem() { return ModItems.BULLET; } public Packet<?> getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } } Registry: public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, MOD_ID); public static final RegistryObject<EntityType<BulletEntity>> BULLET = ENTITIES.register("bullet", () -> EntityType.Builder.<BulletEntity>of(BulletEntity::new, MobCategory.MISC) .sized(0.5F, 0.5F) .setShouldReceiveVelocityUpdates(true) .setTrackingRange(4) .setUpdateInterval(20) .build("bullet")); public ExampleMod() { ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus()); MinecraftForge.EVENT_BUS.register(this); }
  20. Swapped the entity to a RegistryObject, but now getting a constructor error in my Entity Class: Cannot resolve constructor 'BulletEntity' Registry: public static final RegistryObject<EntityType<? extends BulletEntity>> BULLET = ENTITIES.register("bullet", () -> EntityType.Builder.of(BulletEntity::new, MobCategory.MISC) .sized(0.5F, 0.5F) .setShouldReceiveVelocityUpdates(true) .setTrackingRange(4) .setUpdateInterval(20) .build("bullet")); Class constructors: public BulletEntity(EntityType<? extends BulletEntity> type, Level level) { super(type, level); } public BulletEntity(Level level, float damage, int pierceLevel) { super(ExampleMod.BULLET.get(), level); this.damage = damage; this.pierceLevel = pierceLevel; this.setNoGravity(true); } The second constructor is used elsewhere to create the projectile in the world, yet the IDE will not stop throwing an error until it is removed or commented out. I ask again if it is possible to change a 2D item texture from a projectile extending ThrowableProjectileEntity using a custom render (extending from ThrownItemRenderer), as that was my original question.
  21. Init: public static EntityType<BulletEntity> BULLET = EntityType.Builder.<BulletEntity>of(BulletEntity::new, MobCategory.MISC) .sized(0.5F, 0.5F) .setTrackingRange(4) .setUpdateInterval(20) .setShouldReceiveVelocityUpdates(true) .build(MOD_ID + ":bullet"); Entity spawn: @Override public void createProjectile(Player player, Level level, ItemStack stack) { int pierceLevel = EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.FIREPOWER, stack); if (!level.isClientSide) { BulletEntity bullet = new BulletEntity(player, level, getDamage(), pierceLevel); bullet.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 1.5F, 1.0F); level.addFreshEntity(bullet); } }
  22. The entity I created uses the 2D item texture of itself when it spawns since it extends ThrowableItemProjectile, what I want to do is override/change this texture to something else in the renderer if this is possible. Did the following, but didn't have an effect on the texture (unless it isn't supposed to or I am still doing something incorrectly): BulletEntity: @Override public Packet<?> getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } Main mod class: @SubscribeEvent public static void registerRenders(EntityRenderersEvent.RegisterRenderers event) { event.registerEntityRenderer(ExampleMod.BULLET, BulletEntityRenderer::new); }
  23. Is there a way to "override" an entity's texture to something else without creating a "dummy" item when using ThrownItemRenderer? I tried creating a Renderer that extends it with a ResourceLocation override but this does not change the entity's 2D texture. Any help would be appreciated. Render class: public class BulletEntityRenderer extends ThrownItemRenderer { private static final ResourceLocation TEXTURE = new ResourceLocation(ExampleMod.MOD_ID, "textures/entity/bullet.png"); public BulletEntityRenderer(EntityRendererProvider.Context context) { super(context); } @Override public ResourceLocation getTextureLocation(Entity entity) { return TEXTURE; } } Render registry: public class ModRender { public static void registerRender() { EntityRenderers.register(ExampleMod.BULLET, BulletEntityRenderer::new); } } Entity class: public class BulletEntity extends ThrowableItemProjectile { private float damage = 12.0F; private int pierceLevel = 0; private int ticksAlive = 0; private final int lifespan = 60; public BulletEntity(EntityType<BulletEntity> type, Level world) { super(type, world); } public BulletEntity(Player player, Level world, float damage, int pierceLevel) { super(ExampleMod.BULLET, player, world); this.damage = damage; this.pierceLevel = pierceLevel; this.setNoGravity(true); } public DamageSource causeBulletDamage(BulletEntity bullet, Entity attacker) { return (new IndirectEntityDamageSource("bullet", bullet, attacker)).setProjectile(); } public void tick() { super.tick(); Vec3 vec3d = this.getDeltaMovement(); double d1 = vec3d.x; double d2 = vec3d.y; double d0 = vec3d.z; if (this.isInWater()) { this.level.addParticle(ParticleTypes.BUBBLE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } else { this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), -d1, -d2, -d0); } if (ticksAlive > lifespan) { this.discard(); } ticksAlive++; } @Override protected void onHitEntity(EntityHitResult hitResult) { LivingEntity target = (LivingEntity) hitResult.getEntity(); Entity shooter = getOwner(); double armor = target.getArmorValue() * (1 - (0.2 * pierceLevel)); double toughness = target.getAttribute(Attributes.ARMOR_TOUGHNESS).getValue(); float finalDamage = (float) (damage * (1 - (Math.min(20, Math.max((armor / 5), armor - ((4 * damage) / (toughness + 8))))) / 25)); target.hurt(causeBulletDamage(this, shooter).bypassArmor(), finalDamage); } @Override public Item getDefaultItem() { return ModItems.BULLET; } }

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.