use of net.mcft.copy.betterstorage.network.packet.PacketPresentOpen in project BetterStorage by copygirl.
the class TileEntityPresent method onBlockActivated.
@Override
public boolean onBlockActivated(EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
ItemStack holding = player.getCurrentEquippedItem();
if (holding == null) {
if (breakPause > 0)
return false;
breakPause = 10 - breakProgress / 10;
if ((nameTag != null) && !player.getCommandSenderName().equalsIgnoreCase(nameTag)) {
breakPause = 40;
if (!worldObj.isRemote)
((EntityPlayerMP) player).addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "This present is for " + nameTag + ", not you!"));
return false;
}
if ((breakProgress += 20) > 100)
destroyed = true;
if (worldObj.isRemote)
return true;
double x = xCoord + 0.5;
double y = yCoord + 0.5;
double z = zCoord + 0.5;
String sound = Block.soundTypeCloth.getBreakSound();
worldObj.playSoundEffect(x, y, z, sound, 0.75F, 0.8F + breakProgress / 80.0F);
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, sound, 1.0F, 0.4F + breakProgress / 160.0F);
BetterStorage.networkChannel.sendToAllAround(new PacketPresentOpen(xCoord, yCoord, zCoord, destroyed), worldObj, x, y, z, 64);
if (!destroyed)
return true;
if (BetterStorageTiles.cardboardBox != null) {
if (worldObj.setBlock(xCoord, yCoord, zCoord, BetterStorageTiles.cardboardBox)) {
TileEntityCardboardBox box = WorldUtils.get(worldObj, xCoord, yCoord, zCoord, TileEntityCardboardBox.class);
box.uses = ItemCardboardBox.getUses();
box.color = color;
System.arraycopy(contents, 0, box.contents, 0, contents.length);
} else
for (ItemStack stack : contents) WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, stack);
} else if (worldObj.setBlockToAir(xCoord, yCoord, zCoord))
for (ItemStack stack : contents) WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, stack);
return true;
} else if ((holding.getItem() == Items.name_tag) && (nameTag == null) && holding.hasDisplayName()) {
if (holding.getDisplayName().matches("^[a-zA-Z0-9_]{2,16}$")) {
if (!worldObj.isRemote) {
nameTag = holding.getDisplayName();
holding.stackSize--;
markForUpdate();
}
return true;
} else {
if (!worldObj.isRemote)
((EntityPlayerMP) player).addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "The nametag doesn't seem to contain a valid username."));
return false;
}
} else
return false;
}
Aggregations