• Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hey all,   I'm trying to locate the source of any projectileEntity (so I can set some data on the projectile). Please take a look at my current 'solution'. It does work, but I have a bunch of problems, that I would like to discuss. @Mod.EventBusSubscriber(modid = ElementalCombat.MOD_ID, bus = Bus.FORGE) public class ElementifyProjectileSpawnEvent { @SubscribeEvent public static void elementifyProjectileSpawnEvent(EntityJoinWorldEvent event) { if(!event.getWorld().isRemote()){ // only server side should check Entity entity = event.getEntity(); //check if entity is a new spawning projectile. if(entity instanceof ProjectileEntity) { if(entity.ticksExisted == 0) { System.out.println("Newly spawned projectile found"); ProjectileEntity projectile = (ProjectileEntity) entity; //find livingEntity source. (aka the nearest LivingEntity, that isn't the spawning projectzileEntity? What about dispensers?) Vector3d pos = projectile.getPositionVec(); AxisAlignedBB boundingBox = new AxisAlignedBB(pos.x, pos.y, pos.z, pos.x, pos.y, pos.z); List<Entity> nearbyEntities = event.getWorld().getEntitiesWithinAABBExcludingEntity(projectile, boundingBox); System.out.println("Entity in List: "+ nearbyEntities); //check if only one entity was found. This should be the sourceEntity //if List is empty, then source is a TileEntity (i.e Dispenser). if(nearbyEntities.size() == 1) { LivingEntity sourceEntity = (LivingEntity) nearbyEntities.get(0); // If sourceEntity holds an item, use item data. // If not, use data from sourceEntity as default. IElementalAttackData sourceData; if(sourceEntity.hasItemInSlot(EquipmentSlotType.MAINHAND)){ ItemStack item = sourceEntity.getActiveItemStack(); sourceData = ElementalCombatAPI.getElementalAttackData(item); } else{ sourceData = ElementalCombatAPI.getElementalAttackData(sourceEntity); } //copy elemental attack capability IElementalAttackData projectileData = ElementalCombatAPI.getElementalAttackData(projectile); projectileData.setAttackMap(sourceData.getAttackMap()); } } } } } } The idea was to check the position of a projectile the second it's spawning to figure out the source. This does usually work, but in some cases unintended behaviour occurs: Projectiles shot from Dispensers usually returns an empty list (as it should be). But if an entity stands right in front of the dispenser, the list will be filled with that entity. If the position of the new projectile is not within the hitbox of the sourceEntity, the list will stay empty. This happens for example for Llama spit. In this case, the list should include the Llama Entity, but it doesn't. If sourceEntity is crammed into a hole with other entities, the list will be filled with these other entities aswell. Therefor it is not possible to identify the right sourceEntity. (Put a bunch of creepers into a 1x1 hole and then shot an arrow from within that hole. The list will include some of the creepers, since their hitbox overlaps with the player-hitbox) When joining a world with projectileEntities laying on the ground, the game will be stuck on getEntitiesWithinAABBExcludingEntity() function (happens in Singleplayer. Multiplayer is not tested yet). I have no idea, why this happens.   Trying to figure out the source of the projectile through hitbox comparison, isn't really an elegant solution anyway. Does anyone know of a better method or a fix for my problems?   PS: here is my repo: https://github.com/Tavi007/ElementalCombat  
    • I want to add custom movement types to vanilla entities like; constantly jumping and running towards player. How can I do that, should I override AI and if I should how can I do that. (I'm still pretty new to minecraft modding)
    • Make you own thread, and if you're using 1.12, it isn't supported here anymore.
    • @DeBugger did you find any solutions?      
    • Gotcha, I was able to utilize this and use tick() to check for surrounding blocks.   This method is definitely a way to go for some actions, but unfortunately it didn't work for me,   By putting this in onBlockPlace() and also putting it in tick(), I was able to make someone of a consistent tick loop that ran for every interval that the tick scheduler was set at. However, it was inconsistent as random ticks would overlap it and start new tick loops. Removing  the tickRandomly() also wouldn't work for natural block appearances.   Basically any solution using this was going to lag out my game or just be straight up inconsistent. I really appreciate you showing me how to schedule a tick though, it is what I asked to do in the first place after all.   End Result: I ended up using tickRandomly() and tick() like so:   public MyBlock() { super(Properties.create(Material.ROCK) .harvestTool(ToolType.PICKAXE) .harvestLevel(2) .hardnessAndResistance(2.5f, 7f) .sound(SoundType.field_235583_E_) .func_235861_h_() .tickRandomly() ); } @Override public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand) { super.tick(state, worldIn, pos, rand); if(JavaStuff.randomPercentChance(100)) {   Thanks guys for the help!! 😄
  • Topics

  • Who's Online (See full list)