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
62
63
64
65
66
67
|
package gregtech.common.items.behaviors;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.items.GTGenericBlock;
import gregtech.api.items.MetaBaseItem;
import gregtech.api.util.GTUtil;
import gregtech.api.util.GTUtility;
public class BehaviourSwitchMetadata extends BehaviourNone {
public final int mSwitchIndex;
public final boolean mCheckTarget, mShowModeSwitchTooltip;
public BehaviourSwitchMetadata(int aSwitchIndex) {
this(aSwitchIndex, false);
}
public BehaviourSwitchMetadata(int aSwitchIndex, boolean aCheckTarget) {
this(aSwitchIndex, aCheckTarget, false);
}
public BehaviourSwitchMetadata(int aSwitchIndex, boolean aCheckTarget, boolean aShowModeSwitchTooltip) {
mSwitchIndex = aSwitchIndex;
mCheckTarget = aCheckTarget;
mShowModeSwitchTooltip = aShowModeSwitchTooltip;
}
@Override
public List<String> getAdditionalToolTips(MetaBaseItem aItem, List<String> aList, ItemStack aStack) {
if (mShowModeSwitchTooltip) aList.add(GTUtility.trans("330", "Sneak Rightclick to switch Mode"));
return aList;
}
@Override
public boolean onItemUseFirst(MetaBaseItem aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX,
int aY, int aZ, ForgeDirection side, float aHitX, float aHitY, float aHitZ) {
if (aStack != null && (aPlayer == null || aPlayer.isSneaking()) && !aWorld.isRemote) {
if (mCheckTarget) {
Block aBlock = aWorld.blockExists(aX, aY, aZ) ? aWorld.getBlock(aX, aY, aZ) : Blocks.air;
if (aBlock instanceof GTGenericBlock) {
Items.feather.setDamage(aStack, (short) mSwitchIndex);
GTUtility.updateItemStack(aStack);
return true;
}
if (GTUtil.getTileEntity(aWorld, aX, aY, aZ, true) == null) {
Items.feather.setDamage(aStack, (short) mSwitchIndex);
GTUtility.updateItemStack(aStack);
return true;
}
return false;
}
Items.feather.setDamage(aStack, (short) mSwitchIndex);
GTUtility.updateItemStack(aStack);
return true;
}
return false;
}
}
|