aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/items/behaviors/BehaviourCrowbar.java
blob: 76c215bfd0026ce8136e3c78031bc546bfd3447c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gregtech.common.items.behaviors;

import static gregtech.api.enums.Mods.Railcraft;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import gregtech.api.enums.SoundResource;
import gregtech.api.items.MetaBaseItem;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;

public class BehaviourCrowbar extends BehaviourNone {

    private final int mVanillaCosts;
    private final int mEUCosts;

    public BehaviourCrowbar(int aVanillaCosts, int aEUCosts) {
        this.mVanillaCosts = aVanillaCosts;
        this.mEUCosts = aEUCosts;
    }

    @Override
    public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX,
        int aY, int aZ, ForgeDirection side, float hitX, float hitY, float hitZ) {
        if (aWorld.isRemote) {
            return false;
        }
        if (GTModHandler.getModItem(Railcraft.ID, "fluid.creosote.bucket", 1L) != null) {
            return false;
        }
        Block aBlock = aWorld.getBlock(aX, aY, aZ);
        if (aBlock == null) {
            return false;
        }
        byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ);
        if (aBlock == Blocks.rail) {
            if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) {
                aWorld.isRemote = true;
                aWorld.setBlock(aX, aY, aZ, aBlock, (aMeta + 1) % 10, 0);
                aWorld.isRemote = false;
                GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_BREAK, 1.0F, -1.0F, aX, aY, aZ);
            }
            return true;
        }
        if ((aBlock == Blocks.detector_rail) || (aBlock == Blocks.activator_rail) || (aBlock == Blocks.golden_rail)) {
            if (GTModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) {
                aWorld.isRemote = true;
                aWorld.setBlock(aX, aY, aZ, aBlock, aMeta / 8 * 8 + (aMeta % 8 + 1) % 6, 0);
                aWorld.isRemote = false;
                GTUtility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_BREAK, 1.0F, -1.0F, aX, aY, aZ);
            }
            return true;
        }
        return false;
    }
}