Skip to content

Commit

Permalink
rewrite LighterBehavior, maybe fix lag?
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Sep 4, 2021
1 parent a8f6cf2 commit 605ed5e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main/java/gregtech/common/items/behaviors/LighterBehaviour.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package gregtech.common.items.behaviors;

import gregtech.api.GTValues;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand All @@ -32,23 +35,18 @@ public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity en

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
pos = pos.offset(side);
ItemStack stack = player.getHeldItem(hand);
if (!player.canPlayerEdit(pos, side, stack)) {
return EnumActionResult.FAIL;
} else {
if (world.isAirBlock(pos)) {
world.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0f, GTValues.RNG.nextFloat() * 0.4f + 0.8f);
world.setBlockState(pos, Blocks.FIRE.getDefaultState(), 11);
}
useItemDurability(player, hand, stack, ItemStack.EMPTY);
return EnumActionResult.SUCCESS;
}
if (!tryIgniteBlock(world, pos.offset(side))) {
return EnumActionResult.PASS;
}
useItemDurability(player, hand, stack, ItemStack.EMPTY);
return EnumActionResult.SUCCESS;
}

public boolean tryIgniteBlock(World world, BlockPos pos) {
if (world.isAirBlock(pos)) {
world.setBlockState(pos, Blocks.FIRE.getDefaultState());
return true;
}
return false;
}

@Override
Expand Down

0 comments on commit 605ed5e

Please sign in to comment.