Jump to content

Adil Yilan

Members
  • Posts

    73
  • Joined

  • Last visited

Everything posted by Adil Yilan

  1. I am still not able to find a replacement method for .getValues(). Does anyone know how to get all blocks with specific tag? @DePhoegon I have inspected BlockTagsProvider and ItemTagsProvider but I am not familiar with how to use those. Aren't these supposed to be used with data generators?
  2. .is(..) method is still there where it used to be. Issue was with version of parchment mappings that I was using so method was obfuscated to something else. I have updated to use latest parchment version (from yesterday) and that problem is now gone: 1.18.1-2022.03.06-1.18.2
  3. @DePhoegon I am not sure what exactly are you trying to point out. Methods above were valid in Forge for 1.18.1. Since update to 1.18.2 methods have stopped to exist so there are probably replacement methods that I am trying to find. .is(..) method on BlockState existed before in 1.18.1 .
  4. Not sure how that issue is related to these changes? Is there any way to find replacement methods for .is(...) and .getValues() ?
  5. Hello, Seems that there have been some breaking changes with 1.18.2 regarding the tags. Following code no longer works: public static final Tags.IOptionalNamedTag<Block> MACHINES = BlockTags.createOptional(new ResourceLocation(ExperimentalMod.MODID, "machines")); However, I have managed to change the code to: public static final TagKey<Block> MACHINES = BlockTags.create(new ResourceLocation(ExperimentalMod.MODID, "machines")); Is this valid migration path? There are two additional lines of code that do not work any longer: List<Block> flowers = BlockTags.SMALL_FLOWERS.getValues(); Method .getValues() no longer exists. Is there another way to get all blocks that have specific tag? Same is with .is(...) method: if (!blockState.is(BlockTags.LOGS)) { return; } Is there a different approach now to check if BlockState is tagged with specific tag? Thanks!
  6. I have implemented RpgLauncherItem that launches RpgEntity. This is how it works at the moment: https://vimeo.com/user167486120/review/680142871/22206a0362 I have modeled RPG and RPG launcher in BlockBench and imported them as JSON assets in mod. RpgEntity is using GeckoLib for animation, although there is none at the moment. There are 4 issues on the video above: a) RPG is launched from the feet instead from the eye point - what would be the proper way to set shooting point? b) When launcher is used, it looks as if it is trying to hit the ground - can this animation be disabled? c) Sometimes, RPG goes in totally different direction than the crosshair is targeting - is this related to client/server communication and can that be improved? d) As you can see in the video, RPG is spinning while moving - I have no clue why - haven't added that as an animation any way to prevent this from happening? This is RpgEntity code: public class RpgEntity extends AbstractHurtingProjectile implements IAnimatable { // GeckoLib private final AnimationFactory factory = new AnimationFactory(this); public RpgEntity(EntityType<RpgEntity> entityType, Level level) { super(entityType, level); } public RpgEntity(EntityType<RpgEntity> entityType, LivingEntity player, Level level) { super(entityType, player, player.getViewVector(100).x(), player.getViewVector(100).y(), player.getViewVector(100).z(), level); } public static EntityType<RpgEntity> createType() { Builder<RpgEntity> builder = Builder.of((EntityType.EntityFactory<RpgEntity>)RpgEntity::new, MobCategory.MISC); builder.sized(0.5F, 0.5F); builder.clientTrackingRange(4); builder.updateInterval(20); EntityType<RpgEntity> entityType = builder.build("rpg"); return entityType; } @Override protected void onHitEntity(EntityHitResult pResult) { super.onHitEntity(pResult); this.level.explode(this, this.getX(), this.getY(), this.getZ(), 5.0f, false, BlockInteraction.BREAK); this.discard(); } @Override protected void onHitBlock(BlockHitResult pResult) { super.onHitBlock(pResult); this.level.explode(this, this.getX(), this.getY(), this.getZ(), 5.0f, false, BlockInteraction.BREAK); this.discard(); } @Override public Packet<?> getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } @Override public void registerControllers(AnimationData data) { data.addAnimationController(new AnimationController<RpgEntity>(this, "controller", 0, this::predicate)); } // GeckoLib @Override public AnimationFactory getFactory() { return this.factory; } // GeckoLib private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) { return PlayState.CONTINUE; } } This is RpgLauncherItem code: public class RpgLauncherItem extends Item { public RpgLauncherItem() { super(createProperties()); } private static Properties createProperties() { Properties properties = new Properties(); properties.tab(CreativeModeTab.TAB_COMBAT); properties.stacksTo(1); return properties; } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { ItemStack item = pPlayer.getItemInHand(pUsedHand); if (pLevel.isClientSide()) { return InteractionResultHolder.sidedSuccess(item, true); } RpgEntity rpg = new RpgEntity(ProjectileEntities.RPG.get(), pPlayer, pLevel); pPlayer.level.addFreshEntity(rpg); return InteractionResultHolder.sidedSuccess(item, true); } } Any suggestions on how issues above could be resolved would be really appreciated. I am new to all this and getting rocket to fire properly was already a challenge.
  7. Alright, that's enough information, I will dive into it. Thank you so much!
  8. I need data outside of the running Minecraft instance. If I go with WorldSavedData - where will the data be located physically - as in which files/folders on disk drive?
  9. Because I am new to modding and I have no clue what WorldSavedData or Capability is - basically. So I have this block named PinpointerBlock that should be placed on three locations. When the block is activated on the blue position, it should read information about everything between and save it to JSON. That's the whole idea.
  10. I am trying to extract information about the specific structure into a JSON file that will be used as a template to reconstruct the structure through custom made block. When custom block is placed in the world, it will read information from JSON file and place blocks in the same exact order so that structure is reproduced. That's the idea. This is not going to be part of any publicly distributed mod. It's more of developer tool to export structures in a fast way.
  11. Thank you @diesieben07 , this was exactly what I was looking for. Regarding to best approach to write to file system - can you please point me in the right direction, I would like to use Minecraft/Forge API if one is available. My plan is to have collected information exported in JSON format to file system.
  12. I am looking for a way to read information about the block in the world and save that information to a file system. Later on, I would like to place that block back in the world based on the information from file system. 1) I can access BlockState but I am not sure what would be the proper identifier for specific block state? E.g. if stairs are turned to the north, how would I access information about that specific state of the stairs? 2) For information about the type of block, I can use block.getRegistryName() - is that proper way to get string identifier for specific block? 3) ForgeRegistries.BLOCK.getValue accepts registry name of block. Is that a proper way to get instance of a block based on the registry name stored before? 4) Block class has stateById method that accepts Id. Is this proper way to get specific BlockState? If yes, how can I get the Id parameter? I have been struggling with this for a while so any help would be appreciated.
  13. Great ideas, gonna try them out and let you know if those worked. Thanks!
  14. Maybe I am doing this the wrong way? Is it feasible to remove AI from the mob while the effect has duration? I.e. remove AI goals responsible for wandering and attack? I guess I will have to deal with players and mobs differently?
  15. Hi, I am trying to implement "stun" mob effect which would prevent living entity to move or attack. For prevention of attack I have used LivingAttackEvent like this: @SubscribeEvent public static void onAttacked(final LivingAttackEvent event) { // Get source of the damage. DamageSource damageSource = event.getSource(); // Get reference to entity that caused the damage. Entity entity = damageSource.getEntity(); // IF: Entity is not alive. if (!(entity instanceof LivingEntity)) { return; } // Cast entity to mob. LivingEntity mob = (LivingEntity)entity; // Get reference to level where entity is living. Level level = entity.getLevel(); // IF: Code is executing on the client side. if (level.isClientSide()) { return; } // IF: Mob does not have stunned effect applied. if(!mob.hasEffect(PlayerMobEffects.STUNNED.get())){ return; } // Cancel the event - prevent mob from doing anything. event.setCanceled(true); } However this does not work as expected as mob still makes the attack but damage is not done so it does not really look like a stun - it's more like its damage is reduced to 0. I have managed to totally block mob by canceling LivingUpdateEvent - but that has other side effects as living entity is not updated with anything - can't be damaged, can't be hit/burn by sun - basically it becomes immortal. I have also tried with LivingSetAttackTargetEvent but this event can't be canceled. Is there a way to just stop entity from making an attack? Same question regarding the movement - is there a way to stop living entity from moving? Thanks!
  16. @poopoodice Thanks! So, assuming that I got your comment correctly, would this be a proper way to apply an effect: @Override public void doPostAttack(LivingEntity pAttacker, Entity pTarget, int pLevel) { // IF: Code is executing on the client. if (pAttacker.level.isClientSide()) { return; } // IF: Entity is not living entity. if (!(pTarget instanceof LivingEntity)) { return; } // Cast entity to living entity. LivingEntity mob = (LivingEntity)pTarget; // IF: Player already has effect. if (mob.hasEffect(PlayerMobEffects.STUNNED.get())){ return; } // Calculate hit chance. int hitChance = pLevel * 10; // Create random generator. Random random = new Random(); // Get number between 0 and 99. int roll = random.nextInt(100); // IF: Apply on hit chance was missed. if (roll >= hitChance) { return; } // Calculate duration of the effect int duration = 20 * pLevel; // Create instance of effect. MobEffectInstance effect = new MobEffectInstance(PlayerMobEffects.STUNNED.get(), duration, pLevel); // Apply effect to mob. mob.addEffect(effect); } I have tested the code and it works, although I am not sure if there is smarter way to apply effect. Still need to figure out how to make mob die after it gets stunned.
  17. Hi, I have enchantment named "Stun" that can be applied to weapon and that has 3 levels: Level 1 - 10% chance to stun mob for 1 sec Level 2 - 20% chance to stun mob for 2 secs Level 3 - 30% chance to stun mob for 3 secs Plan is to apply MobEffect named StunnedMobEffect on doPostAttack in enchantment. StunnedMobEffect should have variable duration based on the level of enchantment that was applied on weapon. I am trying to find an example on how to do the following: How can I set duration of effect dynamically? How can I track whether duration has expired? I have found these two methods that can be overriden: public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) { public boolean isDurationEffectTick(int pDuration, int pAmplifier) { But looking at the source code of MobEffect class, I can't figure out what pAmplifier is? Any hints / samples on this would be appreciated.
  18. @diesieben07 Thank you for your hint on DeferredRegister, you were right, that was the reason why it didn't work. However, I've changed to use getItemEnchantmentLevel function instead, and now enchantment is working great // Get item in main hand. ItemStack item = player.getMainHandItem(); // Get level of enchantment on item. int level = EnchantmentHelper.getItemEnchantmentLevel(ToolEnchantments.TIMBER.get(), item); // IF: Enchantement level is not at least 1; if (level < 1) { return; }
  19. Hi, I am trying to determine if item has specific enchant. I have tried with EnchantmentHelper, however statement is not returning true for item that is enchanted: // Get item in main hand. ItemStack item = player.getMainHandItem(); // Get list of enchantements on item. Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(item); // IF: Timber is enchanted on item. if(enchantments.containsKey(ToolEnchantments.TIMBER.get())) { // Mine the block at the position. mineBlock(world, blockPos, item); } My guess is that simple object comparison won't do? What would be proper way to check if enchantment is present on item? This is how ToolEnchantments.TIMBER is defined: public final class ToolEnchantments { public static DeferredRegister<Enchantment> REGISTRY; public static RegistryObject<Enchantment> BLOOM; public static RegistryObject<Enchantment> TIMBER; public static void register(IEventBus eventBus) { REGISTRY = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, ExperimentalMod.MODID); REGISTRY.register("bloom", () -> new BloomEnchantment()); REGISTRY.register("timber", () -> new TimberEnchantment()); REGISTRY.register(eventBus); } }
  20. Final version of working code, with comments: public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { // Create diamond pickaxe ItemStack pickaxe = new ItemStack(Items.DIAMOND_PICKAXE); // Enchant it with silk touch pickaxe.enchant(Enchantments.SILK_TOUCH, 1); // Read coordinates of terraformer int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); for (int i = -8; i <= 8; i++) { for (int j = -8; j <= 8; j++) { // IF: it is not location of terraformer if (!(i == 0 && j == 0)) { // Get position of nearby block BlockPos blockPos = new BlockPos(x + i, y, z + j); // Get state of nearby block BlockState blockstate = level.getBlockState(blockPos); // IF: Block is not air if (!blockstate.isAir()) { // Try resolve blockentity for block BlockEntity blockentity = blockstate.hasBlockEntity() ? level.getBlockEntity(blockPos) : null; // Drop resources from loot table as if they were mined with silk touch Block.dropResources(blockstate, level, blockPos, blockentity, null, pickaxe); // Destroy the block without loot drops level.destroyBlock(blockPos, false); } } } } return InteractionResult.SUCCESS; } Thanks @diesieben07!
  21. Thanks It's working, I will post code as soon as I clean it up for others to use.
  22. As tool - I should create i.e. diamond pickaxe with silk touch and pass it in as argument? What is the reason that I have to call level.destroyBlock afterwards once more? Sorry for asking, I like to understand what am I doing. Thanks!
  23. Hi, I have made a block that once it is activated, it removes all other nearby blocks. To accomplish that, I have used level.destroyBlock(..) method. However, what I would like to accomplish is that once the block is destroyed, it should leave item that is equal what would drop after using silk touch. I.e. after block with iron ore is destroyed, a block of iron ore should remain on the ground that can be looted. I am using Forge for Minecraft 1.18.1. I have read that there used to be a method harvestBlock, but I can't find it anymore. What would be a proper way to make effect of block being harvested with silk touch effect? Thanks! EDIT: This is the code of use method on my TerraformerBlock: public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); for (int i = -8; i <= 8; i++) { for (int j = -8; j <= 8; j++) { if (!(i == 0 && j == 0)) { BlockPos blockPos = new BlockPos(x + i, y, z + j); level.destroyBlock(blockPos, false); } } } return InteractionResult.SUCCESS; }
×
×
  • Create New...

Important Information

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