-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathBlockNpcRedstone.java
More file actions
88 lines (77 loc) · 3.45 KB
/
Copy pathBlockNpcRedstone.java
File metadata and controls
88 lines (77 loc) · 3.45 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package noppes.npcs.blocks;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.gui.GuiRedstonePacket;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.blocks.tiles.TileRedstoneBlock;
import noppes.npcs.constants.EnumGuiType;
public class BlockNpcRedstone extends BlockContainer {
public BlockNpcRedstone() {
super(Material.rock);
}
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9) {
if (par1World.isRemote)
return false;
ItemStack currentItem = player.inventory.getCurrentItem();
if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_REDSTONE)) {
TileEntity tile = par1World.getTileEntity(i, j, k);
NBTTagCompound compound = new NBTTagCompound();
tile.writeToNBT(compound);
PacketHandler.Instance.sendToPlayer(new GuiRedstonePacket(compound), (EntityPlayerMP) player);
return true;
}
return false;
}
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4) {
par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this);
par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this);
par1World.notifyBlocksOfNeighborChange(par2, par3 + 1, par4, this);
par1World.notifyBlocksOfNeighborChange(par2 - 1, par3, par4, this);
par1World.notifyBlocksOfNeighborChange(par2 + 1, par3, par4, this);
par1World.notifyBlocksOfNeighborChange(par2, par3, par4 - 1, this);
par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + 1, this);
}
@Override
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {
onBlockAdded(par1World, par2, par3, par4);
}
@Override
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
if (isActivated(par1IBlockAccess, par2, par3, par4) > 0)
return 0xFF6B68;
else
return super.colorMultiplier(par1IBlockAccess, par2, par3, par4);
}
@Override
public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
return isActivated(par1IBlockAccess, par2, par3, par4);
}
@Override
public int isProvidingStrongPower(IBlockAccess par1World, int par2, int par3, int par4, int par5) {
return isActivated(par1World, par2, par3, par4);
}
@Override
public boolean canProvidePower() {
return true;
}
public int isActivated(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
return par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 1 ? 15 : 0;
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileRedstoneBlock();
}
}