Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

TheRedWaffle

Members
  • Posts

    7
  • Joined

  • Last visited

TheRedWaffle's Achievements

Tree Puncher

Tree Puncher (2/8)

3

Reputation

  1. Ok so everything works in game but the effect display doesn't visibly show the duration changing could this be because I instantly remove and change the effect? Here's the code if (!worldIn.isRemote) { if (!entityLiving.getActivePotionEffects().isEmpty()) { Iterator<EffectInstance> itr = entityLiving.getActivePotionEffects().stream().iterator(); do { EffectInstance effectInstance = itr.next(); int duration = effectInstance.getDuration(); int amplifier = effectInstance.getAmplifier(); duration -= 600; Effect effectPotion = effectInstance.getPotion(); entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); } while (itr.hasNext()); } }
  2. You should be able to use the 'getStateForPlacement' method found in Block.java to set the life value. This is the code I used for setting the direction of a block public BlockState getStateForPlacement(BlockItemUseContext context) { return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); } For your second problem maybe try using the 'interactWith' method which is found in the AbstractFurnaceBlock.java This is the code I have for a TileEntity I created protected void interactWith(World worldIn, BlockPos pos, PlayerEntity player) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof BrewerTileEntity) { player.openContainer((INamedContainerProvider)tileentity); player.addStat(Stats.INTERACT_WITH_FURNACE); } }
  3. Sweet thanks for the help. Do I need to make my own 'shouldRemove()' method? I have this right now but shouldRemove isn't a real method if (!worldIn.isRemote) { if (!entityLiving.getActivePotionEffects().isEmpty()) { Iterator<EffectInstance> itr = entityLiving.getActivePotionEffects().iterator(); do { EffectInstance effectInstance = itr.next(); int duration = effectInstance.getDuration(); int amplifier = effectInstance.getAmplifier(); duration -= 600; Effect effectPotion = effectInstance.getPotion(); if(shouldRemove(effectInstance)) { entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); } } while (itr.hasNext()); } } Let me know if I have something wrong.
  4. So basically I am trying to make a Mug of Milk remove 30seconds(600ticks) off of every potion effect the player has. Though this causes a crash when I drink the item. (The code is located in the onItemUseFinish function) if (!worldIn.isRemote) { entityLiving.getActivePotionEffects().stream().map(EffectInstance::getEffectInstance).forEach(effect -> { int duration = effect.getDuration(); int amplifier = effect.getAmplifier(); duration -= 600; Effect effectPotion = effect.getPotion(); entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); }); } I looked it up already and it is because in my code I remove the potion effect and then try to access it. Does anyone know a way around this?
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.